diff --git a/packages/nuxt/src/pages/utils.ts b/packages/nuxt/src/pages/utils.ts index 2d3670ad68..a39b4b9ae8 100644 --- a/packages/nuxt/src/pages/utils.ts +++ b/packages/nuxt/src/pages/utils.ts @@ -211,14 +211,6 @@ function prepareRoutes (routes: NuxtPage[], parent?: NuxtPage) { 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 if (parent && route.path.startsWith('/')) { route.path = route.path.slice(1) diff --git a/packages/nuxt/test/pages.test.ts b/packages/nuxt/test/pages.test.ts index d5ff507183..a882f74715 100644 --- a/packages/nuxt/test/pages.test.ts +++ b/packages/nuxt/test/pages.test.ts @@ -96,18 +96,32 @@ describe('pages:generateRoutesFromFiles', () => { { description: 'should generate correct dynamic routes', files: [ + `${pagesDir}/index.vue`, `${pagesDir}/[slug].vue`, `${pagesDir}/[[foo]]`, `${pagesDir}/[[foo]]/index.vue`, `${pagesDir}/[bar]/index.vue`, - `${pagesDir}/sub/[slug].vue`, + `${pagesDir}/nonopt/[slug].vue`, + `${pagesDir}/opt/[[slug]].vue`, `${pagesDir}/[[sub]]/route-[slug].vue` ], output: [ { - name: 'sub-slug', - path: '/sub/:slug', - file: `${pagesDir}/sub/[slug].vue`, + name: 'index', + path: '/', + 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: [] }, {