From d190f743dc529b154d5b10bae351ac8d39f3dc67 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 3 Apr 2023 10:56:44 +0100 Subject: [PATCH] fix(nuxt): end route param tokens manually (#19902) --- packages/nuxt/src/pages/utils.ts | 2 +- packages/nuxt/test/pages.test.ts | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/nuxt/src/pages/utils.ts b/packages/nuxt/src/pages/utils.ts index dc1dd4e4d2..bf6436a2d3 100644 --- a/packages/nuxt/src/pages/utils.ts +++ b/packages/nuxt/src/pages/utils.ts @@ -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)) diff --git a/packages/nuxt/test/pages.test.ts b/packages/nuxt/test/pages.test.ts index 2684e412a0..38fe8d008b 100644 --- a/packages/nuxt/test/pages.test.ts +++ b/packages/nuxt/test/pages.test.ts @@ -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: [] } @@ -91,7 +91,7 @@ describe('pages:generateRoutesFromFiles', () => { }, { name: 'stories-id', - path: '/stories/:id', + path: '/stories/:id()', file: `${pagesDir}/stories/[id].vue`, children: [] } @@ -106,7 +106,7 @@ describe('pages:generateRoutesFromFiles', () => { output: [ { name: 'stories-id', - path: '/stories/:id', + path: '/stories/:id()', file: `${pagesDir}/stories/[id].vue`, children: [] }, @@ -167,7 +167,7 @@ describe('pages:generateRoutesFromFiles', () => { children: [], name: 'slug', file: 'pages/[slug].vue', - path: '/:slug' + path: '/:slug()' }, { children: [ @@ -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: [] }, @@ -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: [] } @@ -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?',