Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt): do not allow catchalls to have child routes #6257

Merged
merged 2 commits into from
Aug 1, 2022
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
3 changes: 2 additions & 1 deletion packages/nuxt/src/pages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export function generateRoutesFromFiles (files: string[], pagesDir: string): Nux
route.name += (route.name && '-') + segmentName

// ex: parent.vue + parent/child.vue
const child = parent.find(parentRoute => parentRoute.name === route.name)
const child = parent.find(parentRoute => parentRoute.name === route.name && !parentRoute.path.endsWith('(.*)*'))

if (child) {
parent = child.children
route.path = ''
Expand Down
42 changes: 42 additions & 0 deletions packages/nuxt/test/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,48 @@ describe('pages:generateRoutesFromFiles', () => {
}
]
},
{
description: 'should generate correct id for catchall (order 1)',
files: [
`${pagesDir}/[...stories].vue`,
`${pagesDir}/stories/[id].vue`
],
output: [
{
name: 'stories',
path: '/:stories(.*)*',
file: `${pagesDir}/[...stories].vue`,
children: []
},
{
name: 'stories-id',
path: '/stories/:id',
file: `${pagesDir}/stories/[id].vue`,
children: []
}
]
},
{
description: 'should generate correct id for catchall (order 2)',
files: [
`${pagesDir}/stories/[id].vue`,
`${pagesDir}/[...stories].vue`
],
output: [
{
name: 'stories-id',
path: '/stories/:id',
file: `${pagesDir}/stories/[id].vue`,
children: []
},
{
name: 'stories',
path: '/:stories(.*)*',
file: `${pagesDir}/[...stories].vue`,
children: []
}
]
},
{
description: 'should generate correct route for snake_case file',
files: [
Expand Down