路由导航守卫

路由导航守卫

router.beforeEach((to, from, next) => {
  // do someting
});
后置钩子(没有 next 参数)
router.afterEach((to, from) => {
  // do someting
});
cont router = new  VueRouter({
 routes: [
  {
    path: "/file",
    component: File,
    beforeEnter: (to, from ,next) => {  //路由独享
       // do someting
    }
   }
 ]
});
data(){
 return{
   pro:"产品"
 }
},
beforeRouteEnter:(to,from,next)=>{
  console.log(to)
  next(vm => {
   console.log(vm.pro)  //只能在回调里获取this ,上面两个可以正常获取this
  })
}