From 970758e050b074ee8085f1b335f2add6bd62dbb2 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 10 Jun 2022 14:15:53 +0100 Subject: [PATCH] revert(nuxt): revert router hotfix #4983 (#5394) --- packages/nuxt/src/pages/utils.ts | 4 --- packages/nuxt/test/pages.test.ts | 48 ++++++++++++++++---------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/packages/nuxt/src/pages/utils.ts b/packages/nuxt/src/pages/utils.ts index fe9b32adb6..d48a61aeb9 100644 --- a/packages/nuxt/src/pages/utils.ts +++ b/packages/nuxt/src/pages/utils.ts @@ -88,15 +88,11 @@ export function generateRoutesFromFiles (files: string[], pagesDir: string): Nux } parent.push(route) - // TODO: https://github.com/vuejs/router/issues/1435 - parent.sort((a, b) => getSortablePath(a.path).localeCompare(getSortablePath(b.path))) } return prepareRoutes(routes) } -const getSortablePath = (path: string) => path.replace(/^\//, '').replace(/:/, 'Z') - function getRoutePath (tokens: SegmentToken[]): string { return tokens.reduce((path, token) => { return ( diff --git a/packages/nuxt/test/pages.test.ts b/packages/nuxt/test/pages.test.ts index a882f74715..9bf0b0a2af 100644 --- a/packages/nuxt/test/pages.test.ts +++ b/packages/nuxt/test/pages.test.ts @@ -112,23 +112,11 @@ describe('pages:generateRoutesFromFiles', () => { 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: [] - }, { children: [], - name: 'bar', - file: 'pages/[bar]/index.vue', - path: '/:bar' + name: 'slug', + file: 'pages/[slug].vue', + path: '/:slug' }, { children: [ @@ -144,9 +132,21 @@ describe('pages:generateRoutesFromFiles', () => { path: '/:foo?' }, { - name: 'slug', - path: '/:slug', - file: `${pagesDir}/[slug].vue`, + children: [], + name: 'bar', + file: 'pages/[bar]/index.vue', + path: '/:bar' + }, + { + name: 'nonopt-slug', + path: '/nonopt/:slug', + file: `${pagesDir}/nonopt/[slug].vue`, + children: [] + }, + { + name: 'opt-slug', + path: '/opt/:slug?', + file: `${pagesDir}/opt/[[slug]].vue`, children: [] }, { @@ -161,17 +161,17 @@ describe('pages:generateRoutesFromFiles', () => { description: 'should generate correct catch-all route', files: [`${pagesDir}/[...slug].vue`, `${pagesDir}/index.vue`], output: [ - { - name: 'index', - path: '/', - file: `${pagesDir}/index.vue`, - children: [] - }, { name: 'slug', path: '/:slug(.*)*', file: `${pagesDir}/[...slug].vue`, children: [] + }, + { + name: 'index', + path: '/', + file: `${pagesDir}/index.vue`, + children: [] } ] },