在使用
nuxt之前,我们正常的route控制语法如下:const route = new Router({
routes:{
[...]
}
})
route.beforeEach(to,from,next){
//进行路由权限校验等方法
}
而使用nuxt,路由默认会根据页面的路径规则自动生成,所以乍一看根本没有配置的地方,所以当我们想要使用类似beforeEach功能的时候,我们就需要自己定义一个小插件啦。步骤如下:
export default ({ app }) => {
app.router.afterEach((to, from) => {
console.log(to.path)
})
}
2、在nuxt.config.js中plugins数组增加'~/plugins/route' 这样就搞定啦。