//使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
const role = localStorage.getItem('ms_username');
if(!role && to.path !== '/login') {
next("/login")
} else if(role && to.path === "/login") {
//登录后,在路由修改不能返回登录,必须点击退出可以返回登录页
next(from.path)
} else{
next()
}
});
vue-router的beforeEach全局守卫
猜你喜欢
转载自blog.csdn.net/qq_42092177/article/details/104815180
今日推荐
周排行