This commit is contained in:
张成
2025-10-20 18:18:27 +08:00
parent 0047086013
commit fd3c1a5563
8 changed files with 479 additions and 107 deletions

View File

@@ -57,6 +57,25 @@ export const setupRouterGuards = (router, ViewUI, homeName = 'home') => {
next({ name: homeName })
}
} else {
// 已登录,检查路由是否存在
if (token && to.matched.length === 0 && to.path !== '/') {
// 路由不存在,可能是动态路由还未加载完成
console.warn('路由未找到:', to.name || to.path, ',尝试等待动态路由加载')
// 等待一小段时间后重试
setTimeout(() => {
// 检查路由是否已经存在
const route = router.resolve(to.path)
if (route && route.matched.length > 0) {
next({ path: to.path, replace: true })
} else {
console.error('路由仍然不存在:', to.name || to.path, ',跳转到首页')
next({ name: homeName, replace: true })
}
}, 150)
return
}
// 其他情况 → 允许访问
next()
}