mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-17 06:01:34 +00:00
Change router.extendRoutes hook to return new router config
This commit is contained in:
parent
459363beea
commit
635ee580e9
@ -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
|
||||
|
13
test/fixtures/with-config/nuxt.config.js
vendored
13
test/fixtures/with-config/nuxt.config.js
vendored
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user