Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: even if the page component exists, we should not keep the page c… #4925

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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