提交 2b3f9de4 编写于 作者: H haoxr

refactor: 代码优化和完善注释

上级 c6c78344
...@@ -14,17 +14,17 @@ const whiteList = ['/login']; ...@@ -14,17 +14,17 @@ const whiteList = ['/login'];
router.beforeEach(async (to, from, next) => { router.beforeEach(async (to, from, next) => {
NProgress.start(); NProgress.start();
const userStore = useUserStoreHook();
const hasToken = getToken(); const hasToken = getToken();
if (hasToken) { if (hasToken) {
if (to.path === '/login') { if (to.path === '/login') {
// if is logged in, redirect to the home page //
next({ path: '/' }); next({ path: '/' });
} else { } else {
const userStore = useUserStoreHook();
const hasRoles = userStore.roles && userStore.roles.length > 0; const hasRoles = userStore.roles && userStore.roles.length > 0;
if (hasRoles) { if (hasRoles) {
// 路由未匹配,跳转404 // 未匹配到任何路由,跳转404
if (to.matched.length === 0) { if (to.matched.length === 0) {
from.name ? next({ name: from.name }) : next('/404'); from.name ? next({ name: from.name }) : next('/404');
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册