路由
This commit is contained in:
@@ -97,6 +97,30 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
dynamicRoutesLoaded = true // ✅ 加载成功后才设置标志
|
dynamicRoutesLoaded = true // ✅ 加载成功后才设置标志
|
||||||
console.log('[Platform Router] 动态路由加载成功')
|
console.log('[Platform Router] 动态路由加载成功')
|
||||||
|
|
||||||
|
// 添加 404 路由(确保它是最后匹配的)
|
||||||
|
if (!notFoundRouteAdded) {
|
||||||
|
router.addRoute({
|
||||||
|
path: '/:pathMatch(.*)*',
|
||||||
|
name: 'NotFound',
|
||||||
|
component: () => Promise.resolve({
|
||||||
|
default: {
|
||||||
|
render: () => h('div', {
|
||||||
|
style: {
|
||||||
|
padding: '20px',
|
||||||
|
textAlign: 'center'
|
||||||
|
}
|
||||||
|
}, '404 - 页面未找到')
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
meta: {
|
||||||
|
title: '404',
|
||||||
|
requiresAuth: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
notFoundRouteAdded = true
|
||||||
|
console.log('[Platform Router] 404 路由已添加')
|
||||||
|
}
|
||||||
|
|
||||||
if (to.path === '/') {
|
if (to.path === '/') {
|
||||||
// 访问根路径,重定向到第一个可用路由
|
// 访问根路径,重定向到第一个可用路由
|
||||||
const firstRoute = getFirstAvailableRoute()
|
const firstRoute = getFirstAvailableRoute()
|
||||||
@@ -115,10 +139,15 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.warn('[Platform Router] 动态路由加载失败,未返回有效数据')
|
console.warn('[Platform Router] 动态路由加载失败,未返回有效数据')
|
||||||
|
// ✅ 加载失败也要调用next()继续导航
|
||||||
|
next()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[Platform Router] 加载动态路由失败:', error)
|
console.error('[Platform Router] 加载动态路由失败:', error)
|
||||||
// 加载失败不设置标志,下次还会尝试加载
|
// ✅ 加载失败不设置标志,下次还会尝试加载,但要调用next()继续导航
|
||||||
|
next()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user