mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-12-25 22:30:19 +08:00
refactor(projects): 精简版+动态路由权限初步
This commit is contained in:
@@ -1,27 +1,29 @@
|
||||
import type { Router } from 'vue-router';
|
||||
import { useTitle } from '@vueuse/core';
|
||||
import { useAppStore } from '@/store';
|
||||
import { handlePagePermission } from './permission';
|
||||
import { useRouteStore } from '@/store';
|
||||
|
||||
/**
|
||||
* 路由守卫函数
|
||||
* @param router - 路由实例
|
||||
*/
|
||||
export function createRouterGuide(router: Router) {
|
||||
const { resetScrollBehavior } = useAppStore();
|
||||
const routeStore = useRouteStore();
|
||||
const { initDynamicRoute } = useRouteStore();
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
if (!routeStore.isAddedDynamicRoute) {
|
||||
await initDynamicRoute(router);
|
||||
next();
|
||||
return;
|
||||
}
|
||||
// 开始 loadingBar
|
||||
window.$loadingBar?.start();
|
||||
// 页面跳转逻辑
|
||||
handlePagePermission(to, from, next);
|
||||
next();
|
||||
});
|
||||
router.afterEach(to => {
|
||||
// 设置document title
|
||||
useTitle(to.meta.title as string);
|
||||
useTitle(to.meta.title);
|
||||
// 结束 loadingBar
|
||||
window.$loadingBar?.finish();
|
||||
// 重置滚动条行为
|
||||
resetScrollBehavior();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user