mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-01 18:07:22 +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$/, '')
|
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
|
// Remove leading / if children route
|
||||||
if (parent && route.path.startsWith('/')) {
|
if (parent && route.path.startsWith('/')) {
|
||||||
route.path = route.path.slice(1)
|
route.path = route.path.slice(1)
|
||||||
|
@ -96,18 +96,32 @@ describe('pages:generateRoutesFromFiles', () => {
|
|||||||
{
|
{
|
||||||
description: 'should generate correct dynamic routes',
|
description: 'should generate correct dynamic routes',
|
||||||
files: [
|
files: [
|
||||||
|
`${pagesDir}/index.vue`,
|
||||||
`${pagesDir}/[slug].vue`,
|
`${pagesDir}/[slug].vue`,
|
||||||
`${pagesDir}/[[foo]]`,
|
`${pagesDir}/[[foo]]`,
|
||||||
`${pagesDir}/[[foo]]/index.vue`,
|
`${pagesDir}/[[foo]]/index.vue`,
|
||||||
`${pagesDir}/[bar]/index.vue`,
|
`${pagesDir}/[bar]/index.vue`,
|
||||||
`${pagesDir}/sub/[slug].vue`,
|
`${pagesDir}/nonopt/[slug].vue`,
|
||||||
|
`${pagesDir}/opt/[[slug]].vue`,
|
||||||
`${pagesDir}/[[sub]]/route-[slug].vue`
|
`${pagesDir}/[[sub]]/route-[slug].vue`
|
||||||
],
|
],
|
||||||
output: [
|
output: [
|
||||||
{
|
{
|
||||||
name: 'sub-slug',
|
name: 'index',
|
||||||
path: '/sub/:slug',
|
path: '/',
|
||||||
file: `${pagesDir}/sub/[slug].vue`,
|
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: []
|
children: []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user