diff --git a/example/playground/routes.json b/example/playground/routes.json index 4dc834dc..dde10c20 100644 --- a/example/playground/routes.json +++ b/example/playground/routes.json @@ -1,9 +1,4 @@ [ - { - "path": "/", - "page": "./src/Root", - "exact": true - }, { "path": "/search", "page": "./src/Search", @@ -19,5 +14,10 @@ "path": "/detail", "page": "./src/Detail", "exact": true + }, + + { + "path": "/", + "page": "./src/Root", } ] \ No newline at end of file diff --git a/packages/Maleo.js/src/build/static/static.ts b/packages/Maleo.js/src/build/static/static.ts index 04de0ada..10c49f7e 100644 --- a/packages/Maleo.js/src/build/static/static.ts +++ b/packages/Maleo.js/src/build/static/static.ts @@ -19,7 +19,7 @@ export const buildStatic = async (staticPages: StaticPages, dir: string) => { Object.keys(staticPages).map(async (p) => { // @ts-ignore - const html = await render({ req: { originalUrl: p }, res: {}, renderStatic: true }); + const html = await render({ req: { url: p }, res: {}, renderStatic: true }); const pageName: string = p.replace(/\/?(\/*)(.+)/, '$2'); const pathStaticDir = path.resolve(cwd, STATIC_BUILD_DIR, `${pageName}.html`); diff --git a/packages/Maleo.js/src/server/render.tsx b/packages/Maleo.js/src/server/render.tsx index 6fb78405..fc8a7d03 100644 --- a/packages/Maleo.js/src/server/render.tsx +++ b/packages/Maleo.js/src/server/render.tsx @@ -48,7 +48,7 @@ export const render = async ({ const { document: Document, routes, wrap: Wrap, app: App } = await getServerAssets(); // matching routes - const matchedRoutes = await matchingRoutes(routes, req.originalUrl); + const matchedRoutes = await matchingRoutes(routes, req.url); if (!matchedRoutes.length) { res.status(404); @@ -56,7 +56,7 @@ export const render = async ({ } // get Wrap props & App props - const matched = await getMatchedRoutes(routes, req.originalUrl, matchedRoutes); + const matched = await getMatchedRoutes(routes, req.url, matchedRoutes); const ctx = { req, res, routes, [MATCHED_ROUTES_KEY]: matched }; const wrapProps = await loadComponentProps(Wrap, ctx); const { _global_ = {} } = wrapProps || {}; @@ -80,7 +80,7 @@ export const render = async ({ if (match.path === '**') { res.status(404); } else if (branch && route.redirectTo && match.path) { - res.redirect(301, req.originalUrl.replace(match.path, route.redirectTo)); + res.redirect(301, req.url.replace(match.path, route.redirectTo)); return; } @@ -198,7 +198,7 @@ export const defaultRenderPage = ({ // in SSR, we need to manually define location object // to be passed in App because withRouter doesn't work on server side - const location = req.originalUrl; + const location = req.url; // Head provider const { HeadProvider, getHeads } = getHeadProvider();