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 }; }