Skip to content

Commit

Permalink
feat: support index default layout (hannoeru#249)
Browse files Browse the repository at this point in the history
Co-authored-by: liho <liho@revenuemonster.my>
Co-authored-by: hanlee <me@hanlee.co>
Co-authored-by: ハン / Han <16288797+hannoeru@users.noreply.github.com>
  • Loading branch information
4 people authored Jun 30, 2022
1 parent 4730294 commit 4370de8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
5 changes: 1 addition & 4 deletions src/resolvers/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ function prepareRoutes(

delete route.rawRoute

if (route.index)
delete route.path

Object.assign(route, options.extendRoute?.(route, parent) || {})
}

Expand Down Expand Up @@ -74,7 +71,7 @@ async function computeReactRoutes(ctx: PageContext): Promise<ReactRoute[]> {
const isIndexRoute = normalizeCase(node, caseSensitive).endsWith('index')

if (!route.path && isIndexRoute) {
route.index = true
route.path = '/'
} else if (!isIndexRoute) {
if (routeStyle === 'remix')
route.path = buildReactRemixRoutePath(node)
Expand Down
20 changes: 10 additions & 10 deletions test/__snapshots__/generate.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const __pages_import_7__ = React.lazy(() => import(\\"/examples/react/src/pages/
const __pages_import_8__ = React.lazy(() => import(\\"/examples/react/src/pages/blog/today/[...all].tsx\\"));
const __pages_import_9__ = React.lazy(() => import(\\"/examples/react/src/pages/blog/today/index.tsx\\"));
const routes = [{\\"caseSensitive\\":false,\\"path\\":\\"*\\",\\"element\\":React.createElement(__pages_import_0__)},{\\"caseSensitive\\":false,\\"path\\":\\"about\\",\\"element\\":React.createElement(__pages_import_1__),\\"children\\":[{\\"caseSensitive\\":false,\\"element\\":React.createElement(__pages_import_2__),\\"index\\":true}]},{\\"caseSensitive\\":false,\\"path\\":\\"components\\",\\"element\\":React.createElement(__pages_import_3__)},{\\"caseSensitive\\":false,\\"element\\":React.createElement(__pages_import_4__),\\"index\\":true},{\\"caseSensitive\\":false,\\"path\\":\\"blog\\",\\"children\\":[{\\"caseSensitive\\":false,\\"path\\":\\"*\\",\\"element\\":React.createElement(__pages_import_5__)},{\\"caseSensitive\\":false,\\"path\\":\\":id\\",\\"element\\":React.createElement(__pages_import_6__)},{\\"caseSensitive\\":false,\\"element\\":React.createElement(__pages_import_7__),\\"index\\":true},{\\"caseSensitive\\":false,\\"path\\":\\"today\\",\\"children\\":[{\\"caseSensitive\\":false,\\"path\\":\\"*\\",\\"element\\":React.createElement(__pages_import_8__)},{\\"caseSensitive\\":false,\\"element\\":React.createElement(__pages_import_9__),\\"index\\":true}]}]}];
const routes = [{\\"caseSensitive\\":false,\\"path\\":\\"*\\",\\"element\\":React.createElement(__pages_import_0__)},{\\"caseSensitive\\":false,\\"path\\":\\"about\\",\\"element\\":React.createElement(__pages_import_1__),\\"children\\":[{\\"caseSensitive\\":false,\\"path\\":\\"\\",\\"element\\":React.createElement(__pages_import_2__)}]},{\\"caseSensitive\\":false,\\"path\\":\\"components\\",\\"element\\":React.createElement(__pages_import_3__)},{\\"caseSensitive\\":false,\\"path\\":\\"/\\",\\"element\\":React.createElement(__pages_import_4__)},{\\"caseSensitive\\":false,\\"path\\":\\"blog\\",\\"children\\":[{\\"caseSensitive\\":false,\\"path\\":\\"*\\",\\"element\\":React.createElement(__pages_import_5__)},{\\"caseSensitive\\":false,\\"path\\":\\":id\\",\\"element\\":React.createElement(__pages_import_6__)},{\\"caseSensitive\\":false,\\"path\\":\\"\\",\\"element\\":React.createElement(__pages_import_7__)},{\\"caseSensitive\\":false,\\"path\\":\\"today\\",\\"children\\":[{\\"caseSensitive\\":false,\\"path\\":\\"*\\",\\"element\\":React.createElement(__pages_import_8__)},{\\"caseSensitive\\":false,\\"path\\":\\"\\",\\"element\\":React.createElement(__pages_import_9__)}]}]}];
export default routes;"
`;
Expand All @@ -31,7 +31,7 @@ exports[`Generate routes > react - match snapshot > routes 1`] = `
{
"caseSensitive": false,
"element": "/examples/react/src/pages/about/index.tsx",
"index": true,
"path": "",
},
],
"element": "/examples/react/src/pages/about.tsx",
Expand All @@ -45,7 +45,7 @@ exports[`Generate routes > react - match snapshot > routes 1`] = `
{
"caseSensitive": false,
"element": "/examples/react/src/pages/index.tsx",
"index": true,
"path": "/",
},
{
"caseSensitive": false,
Expand All @@ -63,7 +63,7 @@ exports[`Generate routes > react - match snapshot > routes 1`] = `
{
"caseSensitive": false,
"element": "/examples/react/src/pages/blog/index.tsx",
"index": true,
"path": "",
},
{
"caseSensitive": false,
Expand All @@ -76,7 +76,7 @@ exports[`Generate routes > react - match snapshot > routes 1`] = `
{
"caseSensitive": false,
"element": "/examples/react/src/pages/blog/today/index.tsx",
"index": true,
"path": "",
},
],
"path": "today",
Expand Down Expand Up @@ -184,7 +184,7 @@ const __pages_import_10__ = React.lazy(() => import(\\"/examples/remix-style/src
const __pages_import_11__ = React.lazy(() => import(\\"/examples/remix-style/src/pages/blog/today/index.tsx\\"));
import __pages_import_12__ from \\"/examples/remix-style/src/pages/index.tsx\\";
const routes = [{\\"caseSensitive\\":false,\\"element\\":React.createElement(__pages_import_0__),\\"children\\":[{\\"caseSensitive\\":false,\\"path\\":\\"product\\",\\"element\\":React.createElement(__pages_import_1__)}]},{\\"caseSensitive\\":false,\\"path\\":\\"sitemap.xml\\",\\"element\\":React.createElement(__pages_import_2__)},{\\"caseSensitive\\":false,\\"path\\":\\"*\\",\\"element\\":React.createElement(__pages_import_3__)},{\\"caseSensitive\\":false,\\"path\\":\\"about\\",\\"element\\":React.createElement(__pages_import_4__),\\"children\\":[{\\"caseSensitive\\":false,\\"element\\":React.createElement(__pages_import_5__),\\"index\\":true}]},{\\"caseSensitive\\":false,\\"path\\":\\"blog/authors\\",\\"element\\":React.createElement(__pages_import_6__)},{\\"caseSensitive\\":false,\\"path\\":\\"blog\\",\\"element\\":React.createElement(__pages_import_7__),\\"children\\":[{\\"caseSensitive\\":false,\\"path\\":\\"*\\",\\"element\\":React.createElement(__pages_import_8__)},{\\"caseSensitive\\":false,\\"path\\":\\":id\\",\\"element\\":React.createElement(__pages_import_9__)},{\\"caseSensitive\\":false,\\"element\\":React.createElement(__pages_import_10__),\\"index\\":true},{\\"caseSensitive\\":false,\\"path\\":\\"today\\",\\"children\\":[{\\"caseSensitive\\":false,\\"element\\":React.createElement(__pages_import_11__),\\"index\\":true}]}]},{\\"caseSensitive\\":false,\\"element\\":React.createElement(__pages_import_12__),\\"index\\":true}];
const routes = [{\\"caseSensitive\\":false,\\"element\\":React.createElement(__pages_import_0__),\\"children\\":[{\\"caseSensitive\\":false,\\"path\\":\\"product\\",\\"element\\":React.createElement(__pages_import_1__)}]},{\\"caseSensitive\\":false,\\"path\\":\\"sitemap.xml\\",\\"element\\":React.createElement(__pages_import_2__)},{\\"caseSensitive\\":false,\\"path\\":\\"*\\",\\"element\\":React.createElement(__pages_import_3__)},{\\"caseSensitive\\":false,\\"path\\":\\"about\\",\\"element\\":React.createElement(__pages_import_4__),\\"children\\":[{\\"caseSensitive\\":false,\\"path\\":\\"\\",\\"element\\":React.createElement(__pages_import_5__)}]},{\\"caseSensitive\\":false,\\"path\\":\\"blog/authors\\",\\"element\\":React.createElement(__pages_import_6__)},{\\"caseSensitive\\":false,\\"path\\":\\"blog\\",\\"element\\":React.createElement(__pages_import_7__),\\"children\\":[{\\"caseSensitive\\":false,\\"path\\":\\"*\\",\\"element\\":React.createElement(__pages_import_8__)},{\\"caseSensitive\\":false,\\"path\\":\\":id\\",\\"element\\":React.createElement(__pages_import_9__)},{\\"caseSensitive\\":false,\\"path\\":\\"\\",\\"element\\":React.createElement(__pages_import_10__)},{\\"caseSensitive\\":false,\\"path\\":\\"today\\",\\"children\\":[{\\"caseSensitive\\":false,\\"path\\":\\"\\",\\"element\\":React.createElement(__pages_import_11__)}]}]},{\\"caseSensitive\\":false,\\"path\\":\\"/\\",\\"element\\":React.createElement(__pages_import_12__)}];
export default routes;"
`;
Expand Down Expand Up @@ -219,7 +219,7 @@ exports[`Generate routes > routeStyle > remix Style match snapshot > routes 1`]
{
"caseSensitive": false,
"element": "/examples/remix-style/src/pages/about/index.tsx",
"index": true,
"path": "",
},
],
"element": "/examples/remix-style/src/pages/about.tsx",
Expand All @@ -246,15 +246,15 @@ exports[`Generate routes > routeStyle > remix Style match snapshot > routes 1`]
{
"caseSensitive": false,
"element": "/examples/remix-style/src/pages/blog/index.tsx",
"index": true,
"path": "",
},
{
"caseSensitive": false,
"children": [
{
"caseSensitive": false,
"element": "/examples/remix-style/src/pages/blog/today/index.tsx",
"index": true,
"path": "",
},
],
"path": "today",
Expand All @@ -266,7 +266,7 @@ exports[`Generate routes > routeStyle > remix Style match snapshot > routes 1`]
{
"caseSensitive": false,
"element": "/examples/remix-style/src/pages/index.tsx",
"index": true,
"path": "/",
},
]
`;
Expand Down

0 comments on commit 4370de8

Please sign in to comment.