From 9ea89f2d8248ca5a16bea704c0b2d7c5b304ec4c Mon Sep 17 00:00:00 2001 From: SuperCuteXiaoSi <1531733886@qq.com> Date: Sat, 9 Jul 2022 15:52:34 +0800 Subject: [PATCH] =?UTF-8?q?fixbug:=20=E4=BF=AE=E5=A4=8D=E9=9D=A2=E5=8C=85?= =?UTF-8?q?=E5=B1=91=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/pageLayouts/components/Breadcrumb/index.vue | 9 ++++++--- src/layouts/pageLayouts/components/Sidebar/index.vue | 1 + src/layouts/pageLayouts/hooks/useNavSideBar.ts | 2 ++ src/router/modules/index.ts | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/layouts/pageLayouts/components/Breadcrumb/index.vue b/src/layouts/pageLayouts/components/Breadcrumb/index.vue index ce435958..ff4ee3d4 100644 --- a/src/layouts/pageLayouts/components/Breadcrumb/index.vue +++ b/src/layouts/pageLayouts/components/Breadcrumb/index.vue @@ -48,16 +48,17 @@ // 当前路由 const route = useRoute(); - const routes = router.options.routes as AppRouteRecordRaw[]; + const routes = (useRouter().options.routes.find((i) => i.path === '/')?.children || + []) as AppRouteRecordRaw[]; // 解析路由匹配的数组 const getBreadcrumb = () => { const matched: AppRouteRecordRaw[] = []; - const parentRoutes = getParentPaths(router.currentRoute.value.path || '', routes); + const parentRoutes = getParentPaths(router.currentRoute.value.path || '', routes || []); // 获取每个父级路径对应的路由信息 parentRoutes.forEach((path) => { if (path !== '/') { - matched.push(findRouteByPath(path, routes[0].children || []) as AppRouteRecordRaw); + matched.push(findRouteByPath(path, routes || []) as AppRouteRecordRaw); } }); const item = multiTabs.find((item) => { @@ -65,8 +66,10 @@ if (item.query) { itemQuery = JSON.parse(JSON.stringify(item.query)); } + if (matched.find((i) => i.path === item.path)) return false; return route.name === item.name && isEqual(route.query, itemQuery); }); + console.log(matched); if (item) matched.push(item as unknown as AppRouteRecordRaw); levelList.value = matched.filter( (item) => item && item.meta && item.meta.title && !item.meta.breadcrumb, diff --git a/src/layouts/pageLayouts/components/Sidebar/index.vue b/src/layouts/pageLayouts/components/Sidebar/index.vue index 2f42daf5..8949fef0 100644 --- a/src/layouts/pageLayouts/components/Sidebar/index.vue +++ b/src/layouts/pageLayouts/components/Sidebar/index.vue @@ -5,6 +5,7 @@ :unique-opened="true" :collapse="appConfigMode.sidebarMode === 'horizontal' ? false : appConfigMode.collapseMenu" :mode="mode" + router @select="(indexPath) => selectMenu(indexPath)" > { selectMenu(findRoute.children[0].path); return; } + if (isUrl(findRoute.path)) return; emitter.emit('siteBarChange', { routeRaw: findRoute, }); diff --git a/src/router/modules/index.ts b/src/router/modules/index.ts index 218a82d8..616b7c07 100644 --- a/src/router/modules/index.ts +++ b/src/router/modules/index.ts @@ -26,6 +26,6 @@ export function configRouteList() { // 先把菜单路由插入根路径 '/' 防止route 初始化警告查找不到路由 const whIndex = whiteRouteModulesList.findIndex((i) => i.path === '/'); - whiteRouteModulesList[whIndex]['children'] = routeModulesList; + if (whiteRouteModulesList[whIndex]) whiteRouteModulesList[whIndex]['children'] = routeModulesList; return { whiteRouteModulesList, routeModulesList }; }