mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 07:40:33 +00:00
parent
93f6a1e4ca
commit
970758e050
@ -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 (
|
||||
|
@ -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: []
|
||||
}
|
||||
]
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user