refactor(projects): 优化路由声明,添加路由模块导入,规范路相关文件夹

This commit is contained in:
Soybean
2021-11-21 18:44:18 +08:00
parent 2fdb5f563f
commit f199794da0
25 changed files with 444 additions and 200 deletions

27
src/router/guard/index.ts Normal file
View File

@ -0,0 +1,27 @@
import type { Router } from 'vue-router';
import { useTitle } from '@vueuse/core';
import { useAppStore } from '@/store';
import { handlePagePermission } from './permission';
/**
* 路由守卫函数
* @param router - 路由实例
*/
export function createRouterGuide(router: Router) {
const { resetScrollBehavior } = useAppStore();
router.beforeEach((to, from, next) => {
// 开始 loadingBar
window.$loadingBar?.start();
// 页面跳转逻辑
handlePagePermission(to, from, next);
});
router.afterEach(to => {
// 设置document title
useTitle(to.meta.title as string);
// 结束 loadingBar
window.$loadingBar?.finish();
// 重置滚动条行为
resetScrollBehavior();
});
}