diff --git a/snowy-admin-web/src/config/route.js b/snowy-admin-web/src/config/route.js index 30a39fdc..21e1d17c 100644 --- a/snowy-admin-web/src/config/route.js +++ b/snowy-admin-web/src/config/route.js @@ -25,7 +25,7 @@ const routes = { children: [] } ], - // 默认首页为个人中心 + // 默认谁都有个人中心 menu: [ { id: '001', @@ -36,8 +36,7 @@ const routes = { title: '个人中心', type: 'menu', hidden: true - }, - children: [] + } } ] } diff --git a/snowy-admin-web/src/router/index.js b/snowy-admin-web/src/router/index.js index cce90dff..1e25b694 100644 --- a/snowy-admin-web/src/router/index.js +++ b/snowy-admin-web/src/router/index.js @@ -107,10 +107,9 @@ router.beforeEach(async (to, from, next) => { if (apiMenu.length === 0) { // 创建默认模块,显示默认菜单 apiMenu[0] = cloneDeep(userRoutes.module[0]) - const userMenu = userRoutes.menu - const childrenApiMenu = apiMenu[0].children - apiMenu[0].children = [...userMenu, ...childrenApiMenu] } + const childrenApiMenu = apiMenu[0].children + apiMenu[0].children = [...childrenApiMenu ? childrenApiMenu : [], ...userRoutes.menu] let menuRouter = filterAsyncRouter(apiMenu) menuRouter = flatAsyncRoutes(menuRouter) menuRouter.forEach((item) => { @@ -147,10 +146,9 @@ router.getMenu = () => { if (apiMenu.length === 0) { // 创建默认模块,显示默认菜单 apiMenu[0] = cloneDeep(userRoutes.module[0]) - const userMenu = userRoutes.menu - const childrenApiMenu = apiMenu[0].children - apiMenu[0].children = [...userMenu, ...childrenApiMenu] } + const childrenApiMenu = apiMenu[0].children + apiMenu[0].children = [...childrenApiMenu ? childrenApiMenu : [], ...userRoutes.menu] return filterUrl(apiMenu) } diff --git a/snowy-admin-web/src/utils/routerUtil.js b/snowy-admin-web/src/utils/routerUtil.js index 7fc1af1d..24905a1e 100644 --- a/snowy-admin-web/src/utils/routerUtil.js +++ b/snowy-admin-web/src/utils/routerUtil.js @@ -8,14 +8,20 @@ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。 * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip */ +import userRoutes from '@/config/route' + // 获取第一个界面 const getIndexMenu = (menu) => { - let indexMenu = menu[0].children[0] - // 如果第一个菜单为目录,接着往下找 - if (indexMenu.meta.type === 'catalog') { - indexMenu = traverseChild(menu) + if (menu[0] && menu[0].children) { + let indexMenu = menu[0].children[0] + // 如果第一个菜单为目录,接着往下找 + if (indexMenu.meta.type === 'catalog') { + indexMenu = traverseChild(menu) + } + return indexMenu + } else { + return userRoutes.menu[0] } - return indexMenu } // 遍历进行判断,其中处理了被隐藏的 const traverseChild = (menu) => {