前置路由守卫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 @ 2022-10-09 16:33  zongkm  阅读(159)  评论(0)    收藏  举报