order Routes

This commit is contained in:
Alexandre Chopin 2016-12-11 16:40:49 +01:00
parent d09fdfb78e
commit af36b495b0

View File

@ -176,15 +176,9 @@ function * generateRoutesAndFiles () {
} }
// Format routes for the lib/app/router.js template // Format routes for the lib/app/router.js template
templateVars.router.routes = this.routes = createRoutes(files, this.srcDir, this.options.router.routes) 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'))) { if (fs.existsSync(join(this.srcDir, 'layouts', 'app.vue'))) {
templateVars.appPath = r(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'))) { if (fs.existsSync(join(this.srcDir, 'layouts', 'error.vue'))) {
templateVars.components.ErrorPage = r(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) route._name = '_' + hash(route.component)
// Update path with regexp in config let lastkey = _.last(keys)
const path = _.result(options, keys.join('.')) const path = _.result(options, keys.join('.'))
if (path && path.regexp) { if (path) {
route.path = route.path.replace(_.last(keys).replace('_', ':'), path.regexp) // Update path with regexp in config
if (path.regexp) {
route.path = route.path.replace(lastkey.replace('_', ':'), path.regexp)
} }
// regex expression in route path escaping for lodash templating if (path.meta) {
// route.path = route.path.replace(/\\/g, '\\\\') route.meta = path.meta
}
if (path.alias) {
route.alias = path.alias
}
}
// Order Routes path
if (lastkey[0] === '_') {
parent.push(route) parent.push(route)
} else {
parent.unshift(route)
}
}) })
return cleanChildrenRoutes(routes) return cleanChildrenRoutes(routes)
} }