mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
order Routes
This commit is contained in:
parent
d09fdfb78e
commit
af36b495b0
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user