美文网首页
没有权限时,默认跳转到error提示页面

没有权限时,默认跳转到error提示页面

作者: IssunRadiance | 来源:发表于2023-05-10 11:01 被阅读0次

使用 router.beforeEach 进行路由拦截

//使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
  if (Cookie.get('BYTE-TOKEN')) { // 有权限-继续
    next()
  } else { // 没有权限时
    if (to.path == '/error') { // 如果已经是error页面, - 继续
      next()
    } else if (to.path == '/') { // 因为这个项目获取token是在首页获取的, 所以如果是首页 - 也要继续
      next()
    } else { // 如果都不是, 跳转的error页面
      next({ path: '/error' })
    }
  }
});

相关文章

网友评论

      本文标题:没有权限时,默认跳转到error提示页面

      本文链接:https://www.haomeiwen.com/subject/kxzdsdtx.html