revert(nuxt): revert router hotfix #4983 (#5394)

This commit is contained in:
Daniel Roe 2022-06-10 14:15:53 +01:00 committed by GitHub
parent 93f6a1e4ca
commit 970758e050
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 28 deletions

View File

@ -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 (

View File

@ -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: []
}
]
},