feat(projects): 路由页面跳转权限完成

This commit is contained in:
Soybean
2022-01-04 00:00:48 +08:00
parent de2057f141
commit 0d2a5629e8
4 changed files with 83 additions and 13 deletions

View File

@@ -1,24 +1,17 @@
import type { Router } from 'vue-router';
import { useTitle } from '@vueuse/core';
import { useRouteStore } from '@/store';
import { handlePagePermission } from './permission';
/**
* 路由守卫函数
* @param router - 路由实例
*/
export function createRouterGuide(router: Router) {
const routeStore = useRouteStore();
const { initDynamicRoute } = useRouteStore();
router.beforeEach(async (to, from, next) => {
if (!routeStore.isAddedDynamicRoute) {
await initDynamicRoute(router);
next();
return;
}
// 开始 loadingBar
window.$loadingBar?.start();
next();
// 页面跳转权限处理
await handlePagePermission(to, from, next, router);
});
router.afterEach(to => {
// 设置document title