mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): 完善路由配置
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
import type { Router } from 'vue-router';
|
||||
import { useTitle } from '@vueuse/core';
|
||||
import { getToken, getLoginRedirectUrl } from '@/utils';
|
||||
import { RouteNameMap, whitelistRoutes } from './routes';
|
||||
|
||||
/**
|
||||
* 路由守卫函数
|
||||
@ -7,9 +10,26 @@ import type { Router } from 'vue-router';
|
||||
export default function createRouterGuide(router: Router) {
|
||||
router.beforeEach((to, from, next) => {
|
||||
window.$loadingBar?.start();
|
||||
next();
|
||||
const token = getToken();
|
||||
if (whitelistRoutes.includes(to.name as string)) {
|
||||
if (to.name === RouteNameMap.get('login') && token) {
|
||||
next('/');
|
||||
return;
|
||||
}
|
||||
next();
|
||||
return;
|
||||
}
|
||||
if (token) {
|
||||
next();
|
||||
} else {
|
||||
const redirectUrl = getLoginRedirectUrl();
|
||||
next({ name: RouteNameMap.get('login'), query: { redirectUrl } });
|
||||
}
|
||||
});
|
||||
router.afterEach(() => {
|
||||
router.afterEach(to => {
|
||||
// 设置document title
|
||||
useTitle(to.meta.title as string);
|
||||
// 结束 loadingBar
|
||||
window.$loadingBar?.finish();
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user