mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 15:22:39 +00:00
Handle wildcard routing order
This commit is contained in:
parent
700577a526
commit
db47df0761
@ -219,21 +219,26 @@ export function createRoutes (files, srcDir) {
|
||||
if (!b.path.length || b.path === '/') {
|
||||
return 1
|
||||
}
|
||||
let i = 0
|
||||
let res = 0
|
||||
let _a = a.path.split('/')
|
||||
let _b = b.path.split('/')
|
||||
for (let i = 0; i < _a.length; i++) {
|
||||
let y = 0
|
||||
let z = 0
|
||||
const _a = a.path.split('/')
|
||||
const _b = b.path.split('/')
|
||||
for (i = 0; i < _a.length; i++) {
|
||||
if (res !== 0) {
|
||||
break
|
||||
}
|
||||
let y = (_a[i].indexOf('*') > -1) ? 2 : (_a[i].indexOf(':') > -1 ? 1 : 0)
|
||||
let z = (_b[i].indexOf('*') > -1) ? 2 : (_b[i].indexOf(':') > -1 ? 1 : 0)
|
||||
y = _a[i] === '*' ? 2 : (_a[i].indexOf(':') > -1 ? 1 : 0)
|
||||
z = _b[i] === '*' ? 2 : (_b[i].indexOf(':') > -1 ? 1 : 0)
|
||||
res = y - z
|
||||
// If a.length >= b.length
|
||||
if (i === _b.length - 1 && res === 0) {
|
||||
res = 1
|
||||
// change order if * found
|
||||
res = _a[i] === '*' ? -1 : 1
|
||||
}
|
||||
}
|
||||
return res === 0 ? -1 : res
|
||||
return res === 0 ? (_a[i - 1] === '*' && _b[i] ? 1 : -1) : res
|
||||
})
|
||||
})
|
||||
return cleanChildrenRoutes(routes)
|
||||
|
@ -75,7 +75,13 @@ test('Check .nuxt/router.js', t => {
|
||||
t.is(routes[12].path, '/:key/:id?')
|
||||
t.is(routes[12].name, 'key-id')
|
||||
// pages/_.vue
|
||||
t.is(routes[13].path, '/*')
|
||||
t.is(routes[13].name, 'all')
|
||||
t.is(routes[13].path, '/*/p/*')
|
||||
t.is(routes[13].name, 'all-p-all')
|
||||
// pages/_/_.vue
|
||||
t.is(routes[14].path, '/*/*')
|
||||
t.is(routes[14].name, 'all-all')
|
||||
// pages/_.vue
|
||||
t.is(routes[15].path, '/*')
|
||||
t.is(routes[15].name, 'all')
|
||||
})
|
||||
})
|
||||
|
0
test/fixtures/dynamic-routes/pages/_/index.vue
vendored
Normal file
0
test/fixtures/dynamic-routes/pages/_/index.vue
vendored
Normal file
0
test/fixtures/dynamic-routes/pages/_/p/_.vue
vendored
Normal file
0
test/fixtures/dynamic-routes/pages/_/p/_.vue
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<h1>pages/_key/_id.vue</h1>
|
||||
</template>
|
3
test/fixtures/dynamic-routes/pages/_slug.vue
vendored
3
test/fixtures/dynamic-routes/pages/_slug.vue
vendored
@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<h1>pages/_slug.vue</h1>
|
||||
</template>
|
@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<h1>pages/test/_.vue</h1>
|
||||
</template>
|
@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<h1>pages/test/index.vue</h1>
|
||||
</template>
|
Loading…
Reference in New Issue
Block a user