我想使用自定义模块将路由添加到我的应用程序。根据{{3}},在modulesContainer类上有extendRoutes
。但是我的“ extendRoutes”方法没有在下面的代码中调用。我在这里想念什么?
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')
})
}
})
}
答案 0 :(得分:0)
extendRoutes函数实际上是路由器属性上的一种方法。您可以这样定义:this.options.router.extendRoutes = (routes, resolve)=>{}