mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 10:04:05 +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)
|
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)
|
return prepareRoutes(routes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getSortablePath = (path: string) => path.replace(/^\//, '').replace(/:/, 'Z')
|
||||||
|
|
||||||
function getRoutePath (tokens: SegmentToken[]): string {
|
function getRoutePath (tokens: SegmentToken[]): string {
|
||||||
return tokens.reduce((path, token) => {
|
return tokens.reduce((path, token) => {
|
||||||
return (
|
return (
|
||||||
|
@ -105,11 +105,17 @@ describe('pages:generateRoutesFromFiles', () => {
|
|||||||
],
|
],
|
||||||
output: [
|
output: [
|
||||||
{
|
{
|
||||||
name: 'slug',
|
name: 'sub-slug',
|
||||||
path: '/:slug',
|
path: '/sub/:slug',
|
||||||
file: `${pagesDir}/[slug].vue`,
|
file: `${pagesDir}/sub/[slug].vue`,
|
||||||
children: []
|
children: []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
children: [],
|
||||||
|
name: 'bar',
|
||||||
|
file: 'pages/[bar]/index.vue',
|
||||||
|
path: '/:bar'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
@ -124,15 +130,9 @@ describe('pages:generateRoutesFromFiles', () => {
|
|||||||
path: '/:foo?'
|
path: '/:foo?'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
children: [],
|
name: 'slug',
|
||||||
name: 'bar',
|
path: '/:slug',
|
||||||
file: 'pages/[bar]/index.vue',
|
file: `${pagesDir}/[slug].vue`,
|
||||||
path: '/:bar'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'sub-slug',
|
|
||||||
path: '/sub/:slug',
|
|
||||||
file: `${pagesDir}/sub/[slug].vue`,
|
|
||||||
children: []
|
children: []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -145,8 +145,14 @@ describe('pages:generateRoutesFromFiles', () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: 'should generate correct catch-all route',
|
description: 'should generate correct catch-all route',
|
||||||
files: [`${pagesDir}/[...slug].vue`],
|
files: [`${pagesDir}/[...slug].vue`, `${pagesDir}/index.vue`],
|
||||||
output: [
|
output: [
|
||||||
|
{
|
||||||
|
name: 'index',
|
||||||
|
path: '/',
|
||||||
|
file: `${pagesDir}/index.vue`,
|
||||||
|
children: []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'slug',
|
name: 'slug',
|
||||||
path: '/:slug(.*)*',
|
path: '/:slug(.*)*',
|
||||||
|
Loading…
Reference in New Issue
Block a user