Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/nuxt/src/pages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
32 changes: 19 additions & 13 deletions packages/nuxt/test/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -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: []
},
{
Expand All @@ -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(.*)*',
Expand Down