前置路由守卫vue

router.beforeEach((to, from, next) => {
  if (!to.query.code) {
    next({
      path: to.path,
      query: { code: "hm" },
    });
  } else {
    next();
  }
});

前置路由 一般使用router.beforeEach

有三个参数

to:去哪个页面;from:从哪个页面来 ;next: 放行函数 next():放行 , next(false):不放行

我这里的例子是写死的状态

posted @   zongkm  阅读(151)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示