mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-09-18 01:36:37 +08:00
23 lines
602 B
TypeScript
23 lines
602 B
TypeScript
import type { Router } from 'vue-router';
|
|
import { useTitle } from '@vueuse/core';
|
|
import { handlePagePermission } from './permission';
|
|
|
|
/**
|
|
* 路由守卫函数
|
|
* @param router - 路由实例
|
|
*/
|
|
export function createRouterGuard(router: Router) {
|
|
router.beforeEach(async (to, from, next) => {
|
|
// 开始 loadingBar
|
|
window.$loadingBar?.start();
|
|
// 页面跳转权限处理
|
|
await handlePagePermission(to, from, next, router);
|
|
});
|
|
router.afterEach(to => {
|
|
// 设置document title
|
|
useTitle(to.meta.title);
|
|
// 结束 loadingBar
|
|
window.$loadingBar?.finish();
|
|
});
|
|
}
|