From f7512ce0220cf360e215167579c687663fc9f345 Mon Sep 17 00:00:00 2001 From: luhc228 <44047106+luhc228@users.noreply.github.com> Date: Wed, 8 Jun 2022 10:18:00 +0800 Subject: [PATCH] fix: can not get the getStaticPaths method (#5325) --- examples/with-prerender-spa/src/routes.ts | 6 ++++-- packages/icejs/package.json | 2 +- packages/plugin-ice-ssr/CHANGELOG.md | 4 ++++ packages/plugin-ice-ssr/package.json | 2 +- packages/plugin-ice-ssr/src/renderPages.ts.ejs | 8 +++++++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/examples/with-prerender-spa/src/routes.ts b/examples/with-prerender-spa/src/routes.ts index 29e8badaa..563edeed0 100644 --- a/examples/with-prerender-spa/src/routes.ts +++ b/examples/with-prerender-spa/src/routes.ts @@ -1,7 +1,9 @@ +import { lazy } from 'ice'; import Home from '@/pages/Home'; -import About from '@/pages/About'; -import Dashboard from '@/pages/Dashboard'; import NotFound from '@/pages/NotFound'; +import Dashboard from '@/pages/Dashboard'; + +const About = lazy(() => import('@/pages/About')); export default [ { diff --git a/packages/icejs/package.json b/packages/icejs/package.json index 237a91d0c..481cdb094 100644 --- a/packages/icejs/package.json +++ b/packages/icejs/package.json @@ -32,7 +32,7 @@ "build-plugin-ice-mpa": "2.1.1", "build-plugin-ice-request": "2.0.0", "build-plugin-ice-router": "2.1.3", - "build-plugin-ice-ssr": "3.1.2", + "build-plugin-ice-ssr": "3.1.3", "build-plugin-ice-store": "2.0.7", "build-plugin-react-app": "2.2.2", "build-plugin-pwa": "1.1.1", diff --git a/packages/plugin-ice-ssr/CHANGELOG.md b/packages/plugin-ice-ssr/CHANGELOG.md index c1cd4dab9..8bbbcc488 100644 --- a/packages/plugin-ice-ssr/CHANGELOG.md +++ b/packages/plugin-ice-ssr/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 3.1.3 + +- [fix] can't get the getStaticPaths method from the dynamic import route component + ## 3.1.2 - [feat] support generate defaultLocale HTML in SSG diff --git a/packages/plugin-ice-ssr/package.json b/packages/plugin-ice-ssr/package.json index 98bb27a9b..c6be8a8e7 100644 --- a/packages/plugin-ice-ssr/package.json +++ b/packages/plugin-ice-ssr/package.json @@ -1,6 +1,6 @@ { "name": "build-plugin-ice-ssr", - "version": "3.1.2", + "version": "3.1.3", "description": "ssr plugin", "author": "ice-admin@alibaba-inc.com", "homepage": "", diff --git a/packages/plugin-ice-ssr/src/renderPages.ts.ejs b/packages/plugin-ice-ssr/src/renderPages.ts.ejs index a57bf8755..371297232 100644 --- a/packages/plugin-ice-ssr/src/renderPages.ts.ejs +++ b/packages/plugin-ice-ssr/src/renderPages.ts.ejs @@ -73,7 +73,13 @@ async function getFlatRoutes(routes, parentPath = '') { route.component = loadable(route.component.dynamicImport); } prev.push(route); - const getStaticPaths = route.getStaticPaths || route.component.getStaticPaths; + // normal import component + let getStaticPaths = route.getStaticPaths || route.component.getStaticPaths; + if (route.component.load) { + // dynamic import component + const loadedPageComponent = await route.component.load(); + getStaticPaths = (loadedPageComponent.default || loadedPageComponent).getStaticPaths; + } if (typeof getStaticPaths === 'function') { const staticPaths = await getStaticPaths(); if (Array.isArray(staticPaths)) {