Reputation: 144
I want to add routes to my application with a custom module. According to the documentation, there is extendRoutes
on the modulesContainer class for that. But my 'extendRoutes' methods is not called in the code below. What am i missing here ?
module.exports = function Gustave() {
this.nuxt.hook('build:before', () => {
const routes = runGustave()
this.options.generate.routes = [...routes, ...this.options.generate.routes]
console.log('hello world') // this code is called as expected
this.extendRoutes = function(routes, resolve) {
console.log('extendRoutes is called !') // this code is not called
routes.push({
name: '_gustave',
path: '/_gustave',
component: resolve(__dirname, 'components/hello.vue')
})
}
})
}
Upvotes: 1
Views: 3745
Reputation: 593
the answer of @danielkelly_io is correct only to make it more clear:
export default function (moduleOptions) {
const options = mergeObjects({}, localOptions, moduleOptions);
...
this.options.router.extendRoutes = (routes, resolve)=>{
routes.push(
{
name: 'whatever',
path: '/whatever',
component: resolve(__dirname, '@/whatever/whatever.vue'),
}
)
}
Upvotes: 2
Reputation: 61
the extendRoutes function is actually a method on the router property. You can define it like so: this.options.router.extendRoutes = (routes, resolve)=>{}
Upvotes: 2