diff --git a/packages/nuxt/src/pages/utils.ts b/packages/nuxt/src/pages/utils.ts index 719f2cd6cd..c63d163427 100644 --- a/packages/nuxt/src/pages/utils.ts +++ b/packages/nuxt/src/pages/utils.ts @@ -74,7 +74,8 @@ export function generateRoutesFromFiles (files: string[], pagesDir: string): Nux route.name += (route.name && '-') + segmentName // ex: parent.vue + parent/child.vue - const child = parent.find(parentRoute => parentRoute.name === route.name) + const child = parent.find(parentRoute => parentRoute.name === route.name && !parentRoute.path.endsWith('(.*)*')) + if (child) { parent = child.children route.path = '' diff --git a/packages/nuxt/test/pages.test.ts b/packages/nuxt/test/pages.test.ts index 9bf0b0a2af..9882d302d2 100644 --- a/packages/nuxt/test/pages.test.ts +++ b/packages/nuxt/test/pages.test.ts @@ -67,6 +67,48 @@ describe('pages:generateRoutesFromFiles', () => { } ] }, + { + description: 'should generate correct id for catchall (order 1)', + files: [ + `${pagesDir}/[...stories].vue`, + `${pagesDir}/stories/[id].vue` + ], + output: [ + { + name: 'stories', + path: '/:stories(.*)*', + file: `${pagesDir}/[...stories].vue`, + children: [] + }, + { + name: 'stories-id', + path: '/stories/:id', + file: `${pagesDir}/stories/[id].vue`, + children: [] + } + ] + }, + { + description: 'should generate correct id for catchall (order 2)', + files: [ + `${pagesDir}/stories/[id].vue`, + `${pagesDir}/[...stories].vue` + ], + output: [ + { + name: 'stories-id', + path: '/stories/:id', + file: `${pagesDir}/stories/[id].vue`, + children: [] + }, + { + name: 'stories', + path: '/:stories(.*)*', + file: `${pagesDir}/[...stories].vue`, + children: [] + } + ] + }, { description: 'should generate correct route for snake_case file', files: [