1
This commit is contained in:
@@ -103,7 +103,6 @@ export default {
|
|||||||
|
|
||||||
// 动态添加路由(重要!解决登录后点击菜单空白的问题)
|
// 动态添加路由(重要!解决登录后点击菜单空白的问题)
|
||||||
if (window.rootVue && window.rootVue.$router) {
|
if (window.rootVue && window.rootVue.$router) {
|
||||||
// 先移除旧的主路由(如果存在)
|
|
||||||
const router = window.rootVue.$router
|
const router = window.rootVue.$router
|
||||||
const routes = router.options.routes
|
const routes = router.options.routes
|
||||||
|
|
||||||
@@ -115,7 +114,7 @@ export default {
|
|||||||
|
|
||||||
// 添加新的主路由
|
// 添加新的主路由
|
||||||
router.addRoute(mainMenu)
|
router.addRoute(mainMenu)
|
||||||
console.log('动态路由已添加')
|
console.log('动态路由已添加,redirect 设置为:', mainMenu.redirect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -221,15 +221,13 @@ export default class uiTool {
|
|||||||
component: Main,
|
component: Main,
|
||||||
meta: { title: '首页', notCache: true },
|
meta: { title: '首页', notCache: true },
|
||||||
children: [
|
children: [
|
||||||
// 默认 home 路由,确保登录后能跳转
|
|
||||||
{
|
{
|
||||||
path: '/home',
|
path: '/home',
|
||||||
name: 'home',
|
name: '首页',
|
||||||
meta: { title: '首页', notCache: true },
|
component: HomePage,
|
||||||
component: HomePage || {
|
meta: { title: '首页', notCache: true }
|
||||||
render: h => h('div', { style: { padding: '20px' } }, '欢迎使用管理系统')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,9 +267,44 @@ export default class uiTool {
|
|||||||
if (hasHome) {
|
if (hasHome) {
|
||||||
// 如果权限路由中有 home,使用权限路由的 home(不添加默认首页)
|
// 如果权限路由中有 home,使用权限路由的 home(不添加默认首页)
|
||||||
mainRoute.children = curRoutes
|
mainRoute.children = curRoutes
|
||||||
|
mainRoute.redirect = '/home'
|
||||||
} else {
|
} else {
|
||||||
// 如果权限路由中没有 home,保留默认 home 并添加其他路由
|
// 如果权限路由中没有 home,保留默认 home 并添加其他路由
|
||||||
mainRoute.children = [homeRoute, ...curRoutes]
|
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