Skip to content

Commit

Permalink
fix: even if the page component exists, we should not keep the page c… (
Browse files Browse the repository at this point in the history
  • Loading branch information
yimingjfe authored Nov 8, 2023
1 parent f8312ce commit bf0f008
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 47 deletions.
6 changes: 6 additions & 0 deletions .changeset/wise-eggs-breathe.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions packages/solutions/app-tools/src/analyze/nestedRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 : ''}${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -67,18 +51,10 @@ exports[`nested routes walk 1`] = `
"type": "nested",
},
{
"children": [
{
"_component": "@_modern_js_src/user/[id]/page.tsx",
"children": undefined,
"data": "<ROOT>/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": "<ROOT>/tests/analyze/fixtures/nested-routes/user/[id]/page.data.ts",
"id": "user/(id)/page",
"path": ":id",
"type": "nested",
},
Expand Down
13 changes: 3 additions & 10 deletions packages/solutions/app-tools/tests/analyze/nestedRoutes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
},
Expand Down

0 comments on commit bf0f008

Please sign in to comment.