1
This commit is contained in:
@@ -221,15 +221,13 @@ export default class uiTool {
|
||||
component: Main,
|
||||
meta: { title: '首页', notCache: true },
|
||||
children: [
|
||||
// 默认 home 路由,确保登录后能跳转
|
||||
{
|
||||
path: '/home',
|
||||
name: 'home',
|
||||
meta: { title: '首页', notCache: true },
|
||||
component: HomePage || {
|
||||
render: h => h('div', { style: { padding: '20px' } }, '欢迎使用管理系统')
|
||||
}
|
||||
name: '首页',
|
||||
component: HomePage,
|
||||
meta: { title: '首页', notCache: true }
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
|
||||
@@ -269,9 +267,44 @@ export default class uiTool {
|
||||
if (hasHome) {
|
||||
// 如果权限路由中有 home,使用权限路由的 home(不添加默认首页)
|
||||
mainRoute.children = curRoutes
|
||||
mainRoute.redirect = '/home'
|
||||
} else {
|
||||
// 如果权限路由中没有 home,保留默认 home 并添加其他路由
|
||||
mainRoute.children = [homeRoute, ...curRoutes]
|
||||
mainRoute.redirect = '/home'
|
||||
}
|
||||
|
||||
// 动态设置 redirect 到第一个有效的路由
|
||||
// 优先查找首页路由,如果没有则使用第一个菜单项
|
||||
const findFirstRoute = (routes) => {
|
||||
if (!routes || routes.length === 0) return null
|
||||
|
||||
for (let route of routes) {
|
||||
// 优先查找 /home 路由
|
||||
if (route.path === '/home' || route.path === 'home') {
|
||||
return route.path.startsWith('/') ? route.path : '/' + route.path
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有 home,使用第一个页面路由
|
||||
for (let route of routes) {
|
||||
if (route.type !== '菜单' && route.path) {
|
||||
return route.path.startsWith('/') ? route.path : '/' + route.path
|
||||
}
|
||||
// 如果是菜单,递归查找子路由
|
||||
if (route.children && route.children.length > 0) {
|
||||
const childRoute = findFirstRoute(route.children)
|
||||
if (childRoute) return childRoute
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
const firstRoutePath = findFirstRoute(mainRoute.children)
|
||||
if (firstRoutePath) {
|
||||
mainRoute.redirect = firstRoutePath
|
||||
console.log('主路由 redirect 设置为:', firstRoutePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user