fix routes bug order

This commit is contained in:
Alexandre Chopin 2017-02-09 01:18:29 +01:00
parent bf857e94bb
commit 8661c57e88

View File

@ -256,6 +256,8 @@ function createRoutes (files, srcDir) {
// Order Routes path // Order Routes path
parent.push(route) parent.push(route)
parent.sort((a, b) => { parent.sort((a, b) => {
if (!a.path.length || a.path === '/') { return -1 }
if (!b.path.length || b.path === '/') { return 1 }
var res = 0 var res = 0
var _a = a.path.split('/') var _a = a.path.split('/')
var _b = b.path.split('/') var _b = b.path.split('/')
@ -268,10 +270,10 @@ function createRoutes (files, srcDir) {
res = y - z res = y - z
} }
} else { } else {
res = (res === 0) ? 1 : res res = (res === 0) ? -1 : res
} }
}) })
return res === 0 ? ((_a.length === _b.length) ? _a[_max].length - _b[_max].length : -1) : res return res === 0 ? ((_a.length === _b.length) ? _a[_max].length - _b[_max].length : _b.length - _a.length) : res
}) })
}) })
return cleanChildrenRoutes(routes) return cleanChildrenRoutes(routes)