This commit is contained in:
2026-01-08 16:16:06 +08:00
parent b1e7aeca43
commit b0ddabd819
6 changed files with 62 additions and 11 deletions

View File

@@ -89,11 +89,14 @@ router.beforeEach(async (to, from, next) => {
// 如果已登录且动态路由未加载,先加载动态路由
if (hasToken && !dynamicRoutesLoaded) {
dynamicRoutesLoaded = true
try {
console.log('[Platform Router] 开始加载动态路由...')
const loaded = await loadRoutesFromStorage()
if (loaded) {
dynamicRoutesLoaded = true // ✅ 加载成功后才设置标志
console.log('[Platform Router] 动态路由加载成功')
if (to.path === '/') {
// 访问根路径,重定向到第一个可用路由
const firstRoute = getFirstAvailableRoute()
@@ -106,12 +109,16 @@ router.beforeEach(async (to, from, next) => {
}
} else {
// 动态路由已加载,重新导航到目标路由
console.log('[Platform Router] 重新导航到目标路由:', to.path)
next({ ...to, replace: true })
return
}
} else {
console.warn('[Platform Router] 动态路由加载失败,未返回有效数据')
}
} catch (error) {
console.error('[Platform Router] 加载动态路由失败:', error)
// 加载失败不设置标志,下次还会尝试加载
}
}