Change router.extendRoutes hook to return new router config

This commit is contained in:
Ivan Nikulin 2017-08-21 22:01:41 +02:00
parent 459363beea
commit 635ee580e9
No known key found for this signature in database
GPG Key ID: F800F559F11A1A10
2 changed files with 18 additions and 7 deletions

View File

@ -254,12 +254,20 @@ export default class Builder extends Tapable {
templateVars.router.routes = this.options.build.createRoutes(this.options.srcDir)
}
await this.applyPluginsAsync('extendRoutes', { routes: templateVars.router.routes, templateVars, r })
const extendedRoutes = await this.applyPluginsAsync('extendRoutes', { routes: templateVars.router.routes, templateVars, r })
// Only overwrite routes when something is returned for backwards compatibility
if (extendedRoutes !== undefined) {
templateVars.router.routes = extendedRoutes
}
// router.extendRoutes method
if (typeof this.options.router.extendRoutes === 'function') {
// let the user extend the routes
this.options.router.extendRoutes(templateVars.router.routes, r)
const extendedRoutes = this.options.router.extendRoutes(templateVars.router.routes, r)
// Only overwrite routes when something is returned for backwards compatibility
if (extendedRoutes !== undefined) {
templateVars.router.routes = extendedRoutes
}
}
// Make routes accessible for other modules and webpack configs

View File

@ -4,11 +4,14 @@ module.exports = {
base: '/test/',
middleware: 'noop',
extendRoutes (routes) {
routes.push({
name: 'about-bis',
path: '/about-bis',
component: '~/pages/about.vue'
})
return [
...routes,
{
name: 'about-bis',
path: '/about-bis',
component: '~/pages/about.vue'
}
]
}
},
transition: 'test',