Skip to content

Commit

Permalink
fixbug: 修复面包屑显示问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Jul 9, 2022
1 parent f5271fc commit 9ea89f2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/layouts/pageLayouts/components/Breadcrumb/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,28 @@
// 当前路由
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) => {
let itemQuery = {};
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,
Expand Down
1 change: 1 addition & 0 deletions src/layouts/pageLayouts/components/Sidebar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:unique-opened="true"
:collapse="appConfigMode.sidebarMode === 'horizontal' ? false : appConfigMode.collapseMenu"
:mode="mode"
router
@select="(indexPath) => selectMenu(indexPath)"
>
<sidebar-item
Expand Down
2 changes: 2 additions & 0 deletions src/layouts/pageLayouts/hooks/useNavSideBar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AppRouteRecordRaw } from '#/route';
import { findRouteByPath } from '@/router/utils';
import { usePermissionStoreHook } from '@/store/modules/permission';
import { isUrl } from '@/utils/is';
import { emitter } from '@/utils/mitt';
import { useRouter } from 'vue-router';

Expand All @@ -15,6 +16,7 @@ export const useNavSideBar = () => {
selectMenu(findRoute.children[0].path);
return;
}
if (isUrl(findRoute.path)) return;
emitter.emit('siteBarChange', {
routeRaw: findRoute,
});
Expand Down
2 changes: 1 addition & 1 deletion src/router/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

0 comments on commit 9ea89f2

Please sign in to comment.