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

This commit is contained in:
Daniel Roe 2022-08-01 08:51:46 +01:00 committed by GitHub
parent 5dc864d7bc
commit 96cfe01973
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 1 deletions

View File

@ -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 = ''

View File

@ -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: [