Files
lingji-work-fe/src/router/guard/permission.ts
2025-06-16 14:42:26 +08:00

30 lines
868 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @Author: 田鑫
* @Date: 2023-03-05 14:46:43
* @LastEditors: 田鑫
* @LastEditTime: 2023-03-05 15:55:36
* @Description: 路由权限守卫
*/
import type { Router, RouteRecordNormalized } from 'vue-router';
import NProgress from 'nprogress'; // progress bar
import { useAppStore } from '@/stores';
export default function setupPermissionGuard(router: Router) {
router.beforeEach(async (to, from, next) => {
console.log('access permission router guard');
const appStore = useAppStore();
//* 菜单是否为服务端渲染
if (appStore.menuFromServer) {
//* 没有服务端渲染的菜单
if(!appStore.appAsyncMenus) {
// todo 请求服务端渲染菜单的接口当前为mock数据
await appStore.fetchServerMenuConfig();
}
next();
} else {
next();
}
NProgress.done();
});
}