菜单布局等初步完成
This commit is contained in:
@@ -15,6 +15,7 @@ const WHITE_LIST = [
|
||||
'/login',
|
||||
'/register',
|
||||
'/forgot-password',
|
||||
'/home',
|
||||
'/404',
|
||||
'/403',
|
||||
'/500'
|
||||
@@ -68,7 +69,7 @@ async function handleRouteGuard(
|
||||
store: Store<any>
|
||||
) {
|
||||
const authState: AuthState = store.state.auth;
|
||||
const { isAuthenticated } = store.getters['auth/isAuthenticated'];
|
||||
const isAuthenticated = store.getters['auth/isAuthenticated'];
|
||||
|
||||
// 检查是否在白名单中
|
||||
if (isInWhiteList(to.path)) {
|
||||
@@ -87,15 +88,19 @@ async function handleRouteGuard(
|
||||
}
|
||||
|
||||
// 用户已登录,检查是否需要生成动态路由
|
||||
if (!authState.routesLoaded) {
|
||||
// 注意:通常情况下路由应该在 main.ts 初始化时就已经生成
|
||||
// 这里主要处理登录后首次生成路由的情况
|
||||
if (!authState.routesLoaded && authState.menus && authState.menus.length > 0) {
|
||||
try {
|
||||
console.log('[路由守卫] 路由未加载,开始生成动态路由');
|
||||
// 生成动态路由
|
||||
await store.dispatch('auth/generateRoutes');
|
||||
|
||||
console.log('[路由守卫] 动态路由生成成功,重新导航');
|
||||
// 重新导航到目标路由
|
||||
return next({ ...to, replace: true });
|
||||
} catch (error) {
|
||||
console.error('生成动态路由失败:', error);
|
||||
console.error('[路由守卫] 生成动态路由失败:', error);
|
||||
// 清除认证信息并跳转到登录页
|
||||
store.commit('auth/CLEAR_AUTH');
|
||||
return next('/login');
|
||||
|
||||
Reference in New Issue
Block a user