refactor: 代码优化和完善注释

Former-commit-id: 2b3f9de4667acfa447283e6e8c124c23ad00f0f8
This commit is contained in:
haoxr
2023-02-08 21:22:30 +08:00
parent 5c84761998
commit 8a61ead309

View File

@@ -14,17 +14,17 @@ const whiteList = ['/login'];
router.beforeEach(async (to, from, next) => {
NProgress.start();
const userStore = useUserStoreHook();
const hasToken = getToken();
if (hasToken) {
if (to.path === '/login') {
// if is logged in, redirect to the home page
//
next({ path: '/' });
} else {
const userStore = useUserStoreHook();
const hasRoles = userStore.roles && userStore.roles.length > 0;
if (hasRoles) {
// 路由未匹配跳转404
// 未匹配到任何路由跳转404
if (to.matched.length === 0) {
from.name ? next({ name: from.name }) : next('/404');
} else {