generate routes flatten

This commit is contained in:
Alexandre Chopin 2016-12-12 21:16:12 +01:00
parent b71b8b7478
commit da9c311b54

View File

@ -136,6 +136,9 @@ function * generateRoutesAndFiles () {
** Generate routes based on files
*/
const files = yield glob('pages/**/*.vue', { cwd: this.srcDir })
this.routes = _.uniq(_.map(files, (file) => {
return file.replace(/^pages/, '').replace(/\.vue$/, '').replace('/index', '').replace('_', ':').replace('', '/').replace(/\/{2,}/g, '/')
}))
/*
** Interpret and move template files to .nuxt/
*/
@ -175,7 +178,7 @@ function * generateRoutesAndFiles () {
templateVars.loading = templateVars.loading + '.vue'
}
// Format routes for the lib/app/router.js template
templateVars.router.routes = this.routes = createRoutes(files, this.srcDir)
templateVars.router.routes = createRoutes(files, this.srcDir)
if (fs.existsSync(join(this.srcDir, 'layouts', 'app.vue'))) {
templateVars.appPath = r(this.srcDir, 'layouts/app.vue')
}