Skip to content

Commit

Permalink
fix(nuxt): end route param tokens manually (#19902)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Apr 3, 2023
1 parent 8e9d715 commit d190f74
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/nuxt/src/pages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function getRoutePath (tokens: SegmentToken[]): string {
(token.type === SegmentTokenType.optional
? `:${token.value}?`
: token.type === SegmentTokenType.dynamic
? `:${token.value}`
? `:${token.value}()`
: token.type === SegmentTokenType.catchall
? `:${token.value}(.*)*`
: encodePath(token.value))
Expand Down
27 changes: 17 additions & 10 deletions packages/nuxt/test/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ describe('pages:generateRoutesFromFiles', () => {
output: [
{
name: 'parent-child',
path: '/parent/:child',
path: '/parent/:child()',
file: `${pagesDir}/parent/[child].vue`,
children: []
},
{
name: 'parent-child',
path: '/parent-:child',
path: '/parent-:child()',
file: `${pagesDir}/parent-[child].vue`,
children: []
}
Expand All @@ -91,7 +91,7 @@ describe('pages:generateRoutesFromFiles', () => {
},
{
name: 'stories-id',
path: '/stories/:id',
path: '/stories/:id()',
file: `${pagesDir}/stories/[id].vue`,
children: []
}
Expand All @@ -106,7 +106,7 @@ describe('pages:generateRoutesFromFiles', () => {
output: [
{
name: 'stories-id',
path: '/stories/:id',
path: '/stories/:id()',
file: `${pagesDir}/stories/[id].vue`,
children: []
},
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('pages:generateRoutesFromFiles', () => {
children: [],
name: 'slug',
file: 'pages/[slug].vue',
path: '/:slug'
path: '/:slug()'
},
{
children: [
Expand All @@ -186,11 +186,11 @@ describe('pages:generateRoutesFromFiles', () => {
children: [],
name: 'bar',
file: 'pages/[bar]/index.vue',
path: '/:bar'
path: '/:bar()'
},
{
name: 'nonopt-slug',
path: '/nonopt/:slug',
path: '/nonopt/:slug()',
file: `${pagesDir}/nonopt/[slug].vue`,
children: []
},
Expand All @@ -202,7 +202,7 @@ describe('pages:generateRoutesFromFiles', () => {
},
{
name: 'sub-route-slug',
path: '/:sub?/route-:slug',
path: '/:sub?/route-:slug()',
file: `${pagesDir}/[[sub]]/route-[slug].vue`,
children: []
}
Expand Down Expand Up @@ -243,22 +243,29 @@ describe('pages:generateRoutesFromFiles', () => {
files: [
`${pagesDir}/[a1_1a].vue`,
`${pagesDir}/[b2.2b].vue`,
`${pagesDir}/[b2]_[2b].vue`,
`${pagesDir}/[[c3@3c]].vue`,
`${pagesDir}/[[d4-4d]].vue`
],
output: [
{
name: 'a1_1a',
path: '/:a1_1a',
path: '/:a1_1a()',
file: `${pagesDir}/[a1_1a].vue`,
children: []
},
{
name: 'b2.2b',
path: '/:b2.2b',
path: '/:b2.2b()',
file: `${pagesDir}/[b2.2b].vue`,
children: []
},
{
name: 'b2_2b',
path: '/:b2()_:2b()',
file: `${pagesDir}/[b2]_[2b].vue`,
children: []
},
{
name: 'c33c',
path: '/:c33c?',
Expand Down

0 comments on commit d190f74

Please sign in to comment.