Add _name in router template

This commit is contained in:
Sébastien Chopin 2017-01-19 16:25:55 +01:00
parent ef4065b350
commit be6562f244
2 changed files with 6 additions and 3 deletions

View File

@ -9,6 +9,7 @@ Vue.use(Router)
function recursiveRoutes(routes, tab, components) {
var res = ''
routes.forEach((route, i) => {
route._name = '_' + hash(route.component)
components.push({ _name: route._name, component: route.component })
res += tab + '{\n'
res += tab + '\tpath: ' + JSON.stringify(route.path) + ',\n'

View File

@ -205,7 +205,10 @@ function * generateRoutesAndFiles () {
return readFile(r(__dirname, 'app', file), 'utf8')
.then((fileContent) => {
const template = _.template(fileContent, {
imports: { serialize }
imports: {
serialize,
hash
}
})
const content = template(templateVars)
return writeFile(r(this.dir, '.nuxt', file), content, 'utf8')
@ -218,7 +221,7 @@ function createRoutes (files, srcDir) {
let routes = []
files.forEach((file) => {
let keys = file.replace(/^pages/, '').replace(/\.vue$/, '').replace(/\/{2,}/g, '/').split('/').slice(1)
let route = { name: '', path: '', component: r(srcDir, file), _name: null }
let route = { name: '', path: '', component: r(srcDir, file) }
let parent = routes
keys.forEach((key, i) => {
route.name = route.name ? route.name + '-' + key.replace('_', '') : key.replace('_', '')
@ -240,7 +243,6 @@ function createRoutes (files, srcDir) {
}
}
})
route._name = '_' + hash(route.component)
// Order Routes path
parent.push(route)
parent.sort((a, b) => {