Vue 路由传值 路由钩子

88 阅读1分钟

全局路由守卫

/* 进入触发 */
Router.beforeEach((to,from,next)=>{
      ......
})

/* 离开触发 */
Router.afterEach((to,from)=>{
      ......
})

局部路由钩子函数 只针对当前的路由的:

{ 
path:"/home", 
component:resolve=>import("../views/home.vue"),
/* 指定进入 home 时触发,是局部钩子*/
beforeEnter:(to,from,next)=>{ 
    next();
    } 
}

三种组件内路由钩子函数

/* 进入时触发 */
  beforeRouteEnter(to,from,next){
    console.log('进入Vip页面');
    next();
  },

/* 页面更新触发 */
    beforeRouteUpdate(to,from,next) {
    console.log('页面更新了');
    next();
  },
  
 /* 离开页面触发 */ 
    beforeRouteLeave (to, from, next) {
      next();
  }