mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
fix extendRoutes for generate
This commit is contained in:
parent
7b3c62739c
commit
f5300e4e67
24
lib/build.js
24
lib/build.js
@ -155,17 +155,8 @@ function * generateRoutesAndFiles () {
|
||||
if (name === 'error') return
|
||||
layouts[name] = r(this.srcDir, file)
|
||||
})
|
||||
// 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/g, '').replace(/_/g, ':').replace('', '/').replace(/\/{2,}/g, '/')
|
||||
}))
|
||||
if (typeof this.options.router.extendRoutes === 'function') {
|
||||
// let the user extend the routes
|
||||
this.options.router.extendRoutes(this.routes)
|
||||
}
|
||||
// Interpret and move template files to .nuxt/
|
||||
debug('Generating files...')
|
||||
let templatesFiles = [
|
||||
'App.vue',
|
||||
'client.js',
|
||||
@ -210,6 +201,9 @@ function * generateRoutesAndFiles () {
|
||||
// let the user extend the routes
|
||||
this.options.router.extendRoutes(templateVars.router.routes)
|
||||
}
|
||||
// Routes for Generate command
|
||||
this.routes = flatRoutes(templateVars.router.routes, '')
|
||||
debug('Generating files...')
|
||||
if (layoutsFiles.includes('layouts/error.vue')) {
|
||||
templateVars.components.ErrorPage = r(this.srcDir, 'layouts/error.vue')
|
||||
}
|
||||
@ -329,6 +323,18 @@ function cleanChildrenRoutes (routes, isChild = false) {
|
||||
return routes
|
||||
}
|
||||
|
||||
function flatRoutes (router, path) {
|
||||
let routes = []
|
||||
router.forEach((r) => {
|
||||
if (r.children) {
|
||||
routes.concat(flatRoutes(r.children, r.path))
|
||||
} else {
|
||||
routes.push(path + r.path)
|
||||
}
|
||||
})
|
||||
return routes
|
||||
}
|
||||
|
||||
function getWebpackClientConfig () {
|
||||
return clientWebpackConfig.call(this)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user