添加路由权限
This commit is contained in:
+26
-16
@@ -7,22 +7,32 @@ NProgress.configure({
|
|||||||
speed: 500,
|
speed: 500,
|
||||||
});
|
});
|
||||||
|
|
||||||
const writeNames = ["/login"];
|
// 路由守卫
|
||||||
// router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
// NProgress.start();
|
// 获取token和用户信息
|
||||||
// if (sessionStorage.getItem("token")) {
|
const token = sessionStorage.getItem('token')
|
||||||
// if (to.path === "/login") {
|
const userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}')
|
||||||
// next("/");
|
|
||||||
// }
|
// 白名单路由(不需要登录就可以访问的路由)
|
||||||
// return next();
|
const whiteList = ['/login']
|
||||||
// } else {
|
|
||||||
// if (writeNames.includes(to.path)) {
|
// 如果在白名单中,直接放行
|
||||||
// next();
|
if (whiteList.includes(to.path)) {
|
||||||
// } else {
|
next()
|
||||||
// next("/login");
|
return
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
// });
|
// 判断是否登录
|
||||||
|
if (!token || !userInfo.userid) {
|
||||||
|
// 未登录,跳转到登录页
|
||||||
|
next('/login')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 已登录,放行
|
||||||
|
next()
|
||||||
|
})
|
||||||
|
|
||||||
router.afterEach((transition) => {
|
router.afterEach((transition) => {
|
||||||
NProgress.done();
|
NProgress.done();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user