delete option routes.router

This commit is contained in:
Alexandre Chopin 2016-12-12 14:16:47 +01:00
parent cc15926340
commit 32a6f30118
3 changed files with 15 additions and 31 deletions

View File

@ -1,18 +1,18 @@
module.exports = { module.exports = {
router: { router: {
routes: { routes: {
author: { // author: {
alias: '/nuxt' // alias: '/nuxt'
}, // },
users: { // users: {
_id: { // _id: {
regexp: ':id(\\d+)' // regexp: ':id(\\d+)'
// generate: [1, 2, 3, 4] // Need to be finished on generate // // generate: [1, 2, 3, 4] // Need to be finished on generate
} // }
}, // },
posts: { // posts: {
alias: '/articles' // alias: '/articles'
} // }
} }
}, },
// generate: { // generate: {

View File

@ -15,8 +15,6 @@ function recursiveRoutes(routes, tab) {
res += tab + '\tpath: ' + JSON.stringify(route.path) + ',\n' res += tab + '\tpath: ' + JSON.stringify(route.path) + ',\n'
res += tab + '\tcomponent: ' + route._name res += tab + '\tcomponent: ' + route._name
res += (route.name) ? ',\n\t' + tab + 'name: ' + JSON.stringify(route.name) : '' res += (route.name) ? ',\n\t' + tab + 'name: ' + JSON.stringify(route.name) : ''
res += (route.alias) ? ',\n\t' + tab + 'alias: ' + JSON.stringify(route.alias) : ''
res += (route.meta) ? ',\n\t' + tab + 'meta: ' + JSON.stringify(route.meta) : ''
res += (route.children) ? ',\n\t' + tab + 'children: [\n' + recursiveRoutes(routes[i].children, tab + '\t\t') + '\n\t' + tab + ']' : '' res += (route.children) ? ',\n\t' + tab + 'children: [\n' + recursiveRoutes(routes[i].children, tab + '\t\t') + '\n\t' + tab + ']' : ''
res += '\n' + tab + '}' + (i + 1 === routes.length ? '' : ',\n') res += '\n' + tab + '}' + (i + 1 === routes.length ? '' : ',\n')
}) })

View File

@ -175,7 +175,7 @@ function * generateRoutesAndFiles () {
templateVars.loading = templateVars.loading + '.vue' templateVars.loading = templateVars.loading + '.vue'
} }
// 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)
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')
} }
@ -193,7 +193,7 @@ function * generateRoutesAndFiles () {
yield moveTemplates yield moveTemplates
} }
function createRoutes (files, srcDir, options = {}) { function createRoutes (files, srcDir) {
let routes = [] let routes = []
files.forEach((file) => { files.forEach((file) => {
let keys = file.replace(/^pages/, '').replace(/\.vue$/, '').replace(/\/{2,}/g, '/').split('/').slice(1) let keys = file.replace(/^pages/, '').replace(/\.vue$/, '').replace(/\/{2,}/g, '/').split('/').slice(1)
@ -212,22 +212,8 @@ function createRoutes (files, srcDir, options = {}) {
} }
}) })
route._name = '_' + hash(route.component) route._name = '_' + hash(route.component)
let lastkey = _.last(keys)
const path = _.result(options, keys.join('.'))
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 // Order Routes path
if (lastkey[0] === '_') { if (_.last(keys)[0] === '_') {
parent.push(route) parent.push(route)
} else { } else {
parent.unshift(route) parent.unshift(route)