mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(nuxt): handle optional params within a path segment (#23070)
This commit is contained in:
parent
a07b34a6ed
commit
48fa30af92
@ -220,7 +220,7 @@ function parseSegment (segment: string) {
|
||||
if (c === '[' && state === SegmentParserState.dynamic) {
|
||||
state = SegmentParserState.optional
|
||||
}
|
||||
if (c === ']' && (state !== SegmentParserState.optional || buffer[buffer.length - 1] === ']')) {
|
||||
if (c === ']' && (state !== SegmentParserState.optional || segment[i - 1] === ']')) {
|
||||
if (!buffer) {
|
||||
throw new Error('Empty param')
|
||||
} else {
|
||||
|
@ -157,6 +157,10 @@ describe('pages:generateRoutesFromFiles', () => {
|
||||
{ path: `${pagesDir}/[slug].vue` },
|
||||
{ path: `${pagesDir}/[[foo]]` },
|
||||
{ path: `${pagesDir}/[[foo]]/index.vue` },
|
||||
{ path: `${pagesDir}/optional/[[opt]].vue` },
|
||||
{ path: `${pagesDir}/optional/prefix-[[opt]].vue` },
|
||||
{ path: `${pagesDir}/optional/[[opt]]-postfix.vue` },
|
||||
{ path: `${pagesDir}/optional/prefix-[[opt]]-postfix.vue` },
|
||||
{ path: `${pagesDir}/[bar]/index.vue` },
|
||||
{ path: `${pagesDir}/nonopt/[slug].vue` },
|
||||
{ path: `${pagesDir}/opt/[[slug]].vue` },
|
||||
@ -188,6 +192,31 @@ describe('pages:generateRoutesFromFiles', () => {
|
||||
file: 'pages/[[foo]]',
|
||||
path: '/:foo?'
|
||||
},
|
||||
{
|
||||
children: [],
|
||||
path: '/optional/:opt?',
|
||||
name: 'optional-opt',
|
||||
file: `${pagesDir}/optional/[[opt]].vue`
|
||||
},
|
||||
{
|
||||
children: [],
|
||||
path: '/optional/prefix-:opt?',
|
||||
name: 'optional-prefix-opt',
|
||||
file: `${pagesDir}/optional/prefix-[[opt]].vue`
|
||||
},
|
||||
|
||||
{
|
||||
children: [],
|
||||
path: '/optional/:opt?-postfix',
|
||||
name: 'optional-opt-postfix',
|
||||
file: `${pagesDir}/optional/[[opt]]-postfix.vue`
|
||||
},
|
||||
{
|
||||
children: [],
|
||||
path: '/optional/prefix-:opt?-postfix',
|
||||
name: 'optional-prefix-opt-postfix',
|
||||
file: `${pagesDir}/optional/prefix-[[opt]]-postfix.vue`
|
||||
},
|
||||
{
|
||||
children: [],
|
||||
name: 'bar',
|
||||
|
Loading…
Reference in New Issue
Block a user