mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(nuxt): sort routes with dynamic params at the end (#4983)
This commit is contained in:
parent
775a904c77
commit
b31186b658
@ -88,11 +88,15 @@ 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 (
|
||||
|
@ -105,11 +105,17 @@ describe('pages:generateRoutesFromFiles', () => {
|
||||
],
|
||||
output: [
|
||||
{
|
||||
name: 'slug',
|
||||
path: '/:slug',
|
||||
file: `${pagesDir}/[slug].vue`,
|
||||
name: 'sub-slug',
|
||||
path: '/sub/:slug',
|
||||
file: `${pagesDir}/sub/[slug].vue`,
|
||||
children: []
|
||||
},
|
||||
{
|
||||
children: [],
|
||||
name: 'bar',
|
||||
file: 'pages/[bar]/index.vue',
|
||||
path: '/:bar'
|
||||
},
|
||||
{
|
||||
children: [
|
||||
{
|
||||
@ -124,15 +130,9 @@ describe('pages:generateRoutesFromFiles', () => {
|
||||
path: '/:foo?'
|
||||
},
|
||||
{
|
||||
children: [],
|
||||
name: 'bar',
|
||||
file: 'pages/[bar]/index.vue',
|
||||
path: '/:bar'
|
||||
},
|
||||
{
|
||||
name: 'sub-slug',
|
||||
path: '/sub/:slug',
|
||||
file: `${pagesDir}/sub/[slug].vue`,
|
||||
name: 'slug',
|
||||
path: '/:slug',
|
||||
file: `${pagesDir}/[slug].vue`,
|
||||
children: []
|
||||
},
|
||||
{
|
||||
@ -145,8 +145,14 @@ describe('pages:generateRoutesFromFiles', () => {
|
||||
},
|
||||
{
|
||||
description: 'should generate correct catch-all route',
|
||||
files: [`${pagesDir}/[...slug].vue`],
|
||||
files: [`${pagesDir}/[...slug].vue`, `${pagesDir}/index.vue`],
|
||||
output: [
|
||||
{
|
||||
name: 'index',
|
||||
path: '/',
|
||||
file: `${pagesDir}/index.vue`,
|
||||
children: []
|
||||
},
|
||||
{
|
||||
name: 'slug',
|
||||
path: '/:slug(.*)*',
|
||||
|
Loading…
Reference in New Issue
Block a user