mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 09:02:03 +00:00
fix(nuxt): keep route param optionality when sibling is an index (#5300)
This commit is contained in:
parent
b31186b658
commit
27a0084b6c
@ -211,14 +211,6 @@ function prepareRoutes (routes: NuxtPage[], parent?: NuxtPage) {
|
||||
route.name = route.name.replace(/-index$/, '')
|
||||
}
|
||||
|
||||
if (route.path === '/') {
|
||||
// Remove ? suffix when index page at same level
|
||||
routes.forEach((siblingRoute) => {
|
||||
if (siblingRoute.path.endsWith('?')) {
|
||||
siblingRoute.path = siblingRoute.path.slice(0, -1)
|
||||
}
|
||||
})
|
||||
}
|
||||
// Remove leading / if children route
|
||||
if (parent && route.path.startsWith('/')) {
|
||||
route.path = route.path.slice(1)
|
||||
|
@ -96,18 +96,32 @@ describe('pages:generateRoutesFromFiles', () => {
|
||||
{
|
||||
description: 'should generate correct dynamic routes',
|
||||
files: [
|
||||
`${pagesDir}/index.vue`,
|
||||
`${pagesDir}/[slug].vue`,
|
||||
`${pagesDir}/[[foo]]`,
|
||||
`${pagesDir}/[[foo]]/index.vue`,
|
||||
`${pagesDir}/[bar]/index.vue`,
|
||||
`${pagesDir}/sub/[slug].vue`,
|
||||
`${pagesDir}/nonopt/[slug].vue`,
|
||||
`${pagesDir}/opt/[[slug]].vue`,
|
||||
`${pagesDir}/[[sub]]/route-[slug].vue`
|
||||
],
|
||||
output: [
|
||||
{
|
||||
name: 'sub-slug',
|
||||
path: '/sub/:slug',
|
||||
file: `${pagesDir}/sub/[slug].vue`,
|
||||
name: 'index',
|
||||
path: '/',
|
||||
file: `${pagesDir}/index.vue`,
|
||||
children: []
|
||||
},
|
||||
{
|
||||
name: 'nonopt-slug',
|
||||
path: '/nonopt/:slug',
|
||||
file: `${pagesDir}/nonopt/[slug].vue`,
|
||||
children: []
|
||||
},
|
||||
{
|
||||
name: 'opt-slug',
|
||||
path: '/opt/:slug?',
|
||||
file: `${pagesDir}/opt/[[slug]].vue`,
|
||||
children: []
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user