refactor: 代码优化和完善注释
Former-commit-id: 2b3f9de4667acfa447283e6e8c124c23ad00f0f8
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user