From af36b495b053aaf692fb702dea8be9b9a3c80b35 Mon Sep 17 00:00:00 2001 From: Alexandre Chopin Date: Sun, 11 Dec 2016 16:40:49 +0100 Subject: [PATCH] order Routes --- lib/build/index.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/build/index.js b/lib/build/index.js index 1d8c291480..1b1cf7a1ee 100644 --- a/lib/build/index.js +++ b/lib/build/index.js @@ -176,15 +176,9 @@ function * generateRoutesAndFiles () { } // Format routes for the lib/app/router.js template templateVars.router.routes = this.routes = createRoutes(files, this.srcDir, this.options.router.routes) - if (files.includes('pages/_app.vue')) { - templateVars.appPath = r(this.srcDir, 'pages/_app.vue') - } if (fs.existsSync(join(this.srcDir, 'layouts', 'app.vue'))) { templateVars.appPath = r(this.srcDir, 'layouts/app.vue') } - if (files.includes('pages/_error.vue')) { - templateVars.components.ErrorPage = r(this.srcDir, 'pages/_error.vue') - } if (fs.existsSync(join(this.srcDir, 'layouts', 'error.vue'))) { templateVars.components.ErrorPage = r(this.srcDir, 'layouts/error.vue') } @@ -218,14 +212,26 @@ function createRoutes (files, srcDir, options = {}) { } }) route._name = '_' + hash(route.component) - // Update path with regexp in config + let lastkey = _.last(keys) const path = _.result(options, keys.join('.')) - if (path && path.regexp) { - route.path = route.path.replace(_.last(keys).replace('_', ':'), path.regexp) + if (path) { + // Update path with regexp in config + if (path.regexp) { + route.path = route.path.replace(lastkey.replace('_', ':'), path.regexp) + } + if (path.meta) { + route.meta = path.meta + } + if (path.alias) { + route.alias = path.alias + } + } + // Order Routes path + if (lastkey[0] === '_') { + parent.push(route) + } else { + parent.unshift(route) } - // regex expression in route path escaping for lodash templating - // route.path = route.path.replace(/\\/g, '\\\\') - parent.push(route) }) return cleanChildrenRoutes(routes) }