diff --git a/.changeset/wise-eggs-breathe.md b/.changeset/wise-eggs-breathe.md new file mode 100644 index 000000000000..7909ba44ff3a --- /dev/null +++ b/.changeset/wise-eggs-breathe.md @@ -0,0 +1,6 @@ +--- +'@modern-js/app-tools': patch +--- + +fix: Even if the page component exists, we should not create the empty layout component +fix: 即使页面组件存在,也不应该创建一个空的 layout component diff --git a/packages/solutions/app-tools/src/analyze/nestedRoutes.ts b/packages/solutions/app-tools/src/analyze/nestedRoutes.ts index 6e07b94d31d5..7765bd0172aa 100644 --- a/packages/solutions/app-tools/src/analyze/nestedRoutes.ts +++ b/packages/solutions/app-tools/src/analyze/nestedRoutes.ts @@ -78,14 +78,12 @@ export const optimizeRoute = ( } const { children } = routeTree; - const hasPage = children.some(child => child.index); if ( !routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config && - !routeTree.clientData && - !hasPage + !routeTree.clientData ) { const newRoutes = children.map(child => { const routePath = `${routeTree.path ? routeTree.path : ''}${ diff --git a/packages/solutions/app-tools/tests/analyze/__snapshots__/nestedRoutes.test.ts.snap b/packages/solutions/app-tools/tests/analyze/__snapshots__/nestedRoutes.test.ts.snap index c8ccce82bd27..036599af60fb 100644 --- a/packages/solutions/app-tools/tests/analyze/__snapshots__/nestedRoutes.test.ts.snap +++ b/packages/solutions/app-tools/tests/analyze/__snapshots__/nestedRoutes.test.ts.snap @@ -12,17 +12,9 @@ exports[`nested routes walk 1`] = ` "_component": "@_modern_js_src/__auth/__shop/layout.tsx", "children": [ { - "children": [ - { - "_component": "@_modern_js_src/__auth/__shop/item/page.tsx", - "children": undefined, - "id": "__auth/__shop/item/page", - "index": true, - "type": "nested", - }, - ], - "id": "__auth/__shop/item/layout", - "isRoot": false, + "_component": "@_modern_js_src/__auth/__shop/item/page.tsx", + "children": undefined, + "id": "__auth/__shop/item/page", "path": "item", "type": "nested", }, @@ -32,17 +24,9 @@ exports[`nested routes walk 1`] = ` "type": "nested", }, { - "children": [ - { - "_component": "@_modern_js_src/__auth/login/page.tsx", - "children": undefined, - "id": "__auth/login/page", - "index": true, - "type": "nested", - }, - ], - "id": "__auth/login/layout", - "isRoot": false, + "_component": "@_modern_js_src/__auth/login/page.tsx", + "children": undefined, + "id": "__auth/login/page", "path": "login", "type": "nested", }, @@ -67,18 +51,10 @@ exports[`nested routes walk 1`] = ` "type": "nested", }, { - "children": [ - { - "_component": "@_modern_js_src/user/[id]/page.tsx", - "children": undefined, - "data": "/tests/analyze/fixtures/nested-routes/user/[id]/page.data.ts", - "id": "user/(id)/page", - "index": true, - "type": "nested", - }, - ], - "id": "user/(id)/layout", - "isRoot": false, + "_component": "@_modern_js_src/user/[id]/page.tsx", + "children": undefined, + "data": "/tests/analyze/fixtures/nested-routes/user/[id]/page.data.ts", + "id": "user/(id)/page", "path": ":id", "type": "nested", }, diff --git a/packages/solutions/app-tools/tests/analyze/nestedRoutes.test.ts b/packages/solutions/app-tools/tests/analyze/nestedRoutes.test.ts index 5764ac412acc..5a50060ea07c 100644 --- a/packages/solutions/app-tools/tests/analyze/nestedRoutes.test.ts +++ b/packages/solutions/app-tools/tests/analyze/nestedRoutes.test.ts @@ -163,17 +163,10 @@ describe('nested routes', () => { _component: 'layoutB', children: [ { - id: 'c', - type: 'nested', + id: 'd', path: 'c', - children: [ - { - id: 'd', - type: 'nested', - _component: 'pageD', - index: true, - }, - ], + _component: 'pageD', + type: 'nested', }, ], },