From e233c5def8a8f9f827847d9b019008421a9f9bc8 Mon Sep 17 00:00:00 2001 From: Alexandre Chopin Date: Fri, 3 Feb 2017 20:23:28 +0100 Subject: [PATCH] fix bug routes and add _.vue support (all) --- lib/build.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/build.js b/lib/build.js index 987a6aa088..de4edba1d9 100644 --- a/lib/build.js +++ b/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)