没有权限时,默认跳转到error提示页面
2023-05-10 本文已影响0人
IssunRadiance
使用 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' })
}
}
});