init
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user