mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 22:25:12 +00:00
fix bug routes and add _.vue support (all)
This commit is contained in:
parent
17650c25e0
commit
e233c5def8
24
lib/build.js
24
lib/build.js
@ -234,6 +234,7 @@ function createRoutes (files, srcDir) {
|
||||
let parent = routes
|
||||
keys.forEach((key, i) => {
|
||||
route.name = route.name ? route.name + '-' + key.replace('_', '') : key.replace('_', '')
|
||||
route.name += (key === '_') ? 'all' : ''
|
||||
let child = _.find(parent, { name: route.name })
|
||||
if (child) {
|
||||
if (!child.children) {
|
||||
@ -245,8 +246,8 @@ function createRoutes (files, srcDir) {
|
||||
if (key === 'index' && (i + 1) === keys.length) {
|
||||
route.path += (i > 0 ? '' : '/')
|
||||
} else {
|
||||
route.path += '/' + key.replace('_', ':')
|
||||
if (key.includes('_')) {
|
||||
route.path += '/' + (key === '_' ? '*' : key.replace('_', ':'))
|
||||
if (key !== '_' && key.indexOf('_') !== -1) {
|
||||
route.path += '?'
|
||||
}
|
||||
}
|
||||
@ -255,9 +256,22 @@ function createRoutes (files, srcDir) {
|
||||
// Order Routes path
|
||||
parent.push(route)
|
||||
parent.sort((a, b) => {
|
||||
var isA = (a.path[0] === ':' || a.path[1] === ':') ? 1 : 0
|
||||
var isB = (b.path[0] === ':' || b.path[1] === ':') ? 1 : 0
|
||||
return (isA - isB === 0) ? a.path.length - b.path.length : isA - isB
|
||||
var res = 0
|
||||
var _a = a.path.split('/')
|
||||
var _b = b.path.split('/')
|
||||
var _max = _b.length - 1
|
||||
_a.forEach((s, i) => {
|
||||
if (i <= _max) {
|
||||
if (res === 0) {
|
||||
var y = (s.indexOf('*') > -1) ? 2 : (s.indexOf(':') > -1 ? 1 : 0)
|
||||
var z = (_b[i].indexOf('*') > -1) ? 2 : (_b[i].indexOf(':') > -1 ? 1 : 0)
|
||||
res = y - z
|
||||
}
|
||||
} else {
|
||||
res = (res === 0) ? 1 : res
|
||||
}
|
||||
})
|
||||
return res === 0 ? ((_a.length === _b.length) ? _a[_max].length - _b[_max].length : -1) : res
|
||||
})
|
||||
})
|
||||
return cleanChildrenRoutes(routes)
|
||||
|
Loading…
Reference in New Issue
Block a user