Skip to content

Commit e0dc5cf

Browse files
committed
fix(breadcrumb): ensure that the single-level breadcrumbs jump correctly close #321
1 parent d5d4c4b commit e0dc5cf

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

CHANGELOG.zh_CN.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- 修复树组件 demo 示例样式错误
2222
- 修复账号管理新增未清空旧数据
2323
- form 组件应允许 setFieldsValue 方法值为 null 或者 undefined
24+
- 确保单级面包屑正确跳转
2425

2526
## 2.0.2 (2021-03-04)
2627

src/layouts/default/header/components/Breadcrumb.vue

+36-15
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,40 @@
7272
if (currentRoute.value.meta?.currentActiveMenu) {
7373
filterBreadcrumbList.push((currentRoute.value as unknown) as RouteLocationMatched);
7474
}
75-
// routes.value = filterBreadcrumbList.length === 1 ? [] : filterBreadcrumbList;
76-
routes.value = filterBreadcrumbList;
75+
routes.value = subRouteExtraction(filterBreadcrumbList);
7776
});
7877
78+
function subRouteExtraction(routeList: RouteLocationMatched[]) {
79+
const resultRoutes: RouteLocationMatched[] = [];
80+
routeList.forEach((route) => {
81+
if (route.children?.length === 1) {
82+
const subRoute = route.children[0] as RouteLocationMatched;
83+
const subRouteName = subRoute.name as string;
84+
const routeName = route.name;
85+
if (subRouteName && `${subRouteName}Parent` === routeName) {
86+
route = subRoute;
87+
}
88+
}
89+
resultRoutes.push(route);
90+
});
91+
return resultRoutes;
92+
}
93+
7994
function filterItem(list: RouteLocationMatched[]) {
8095
let resultList = filter(list, (item) => {
8196
const { meta } = item;
8297
8398
if (!meta) {
8499
return false;
85100
}
101+
86102
const { title, hideBreadcrumb, hideMenu } = meta;
87103
if (!title || hideBreadcrumb || hideMenu) {
88104
return false;
89105
}
90-
91106
return true;
92107
}).filter((item) => !item.meta?.hideBreadcrumb || !item.meta?.hideMenu);
93108
94-
// resultList = resultList.filter((item) => item.path !== PageEnum.BASE_HOME);
95109
return resultList;
96110
}
97111
@@ -101,7 +115,8 @@
101115
children,
102116
redirect,
103117
meta,
104-
// components
118+
119+
// components
105120
} = route;
106121
107122
// const isParent =
@@ -123,23 +138,29 @@
123138
if (redirect && isString(redirect)) {
124139
go(redirect);
125140
} else {
126-
const ps = paths.slice(1);
127-
const lastPath = ps.pop() || '';
128-
const parentPath = ps.pop() || '';
129-
let path = `${parentPath}/${lastPath}`;
130-
path = /^\//.test(path) ? path : `/${path}`;
131-
go(path);
141+
let goPath = '';
142+
if (paths.length === 1) {
143+
goPath = paths[0];
144+
} else {
145+
const ps = paths.slice(1);
146+
const lastPath = ps.pop() || '';
147+
const parentPath = ps.pop() || '';
148+
goPath = `${parentPath}/${lastPath}`;
149+
}
150+
goPath = /^\//.test(goPath) ? goPath : `/${goPath}`;
151+
go(goPath);
132152
}
133153
}
134154
135155
function hasRedirect(routes: RouteLocationMatched[], route: RouteLocationMatched) {
136-
if (route?.meta?.isLink) {
137-
return true;
138-
}
139-
140156
if (routes.indexOf(route) === routes.length - 1) {
141157
return false;
142158
}
159+
160+
// if (route?.meta?.isLink) {
161+
// return true;
162+
// }
163+
143164
return true;
144165
}
145166

src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { isDevMode } from '/@/utils/env';
5151

5252
// The development environment takes effect
5353
if (isDevMode()) {
54-
app.config.performance = true;
54+
// app.config.performance = true;
5555
window.__APP__ = app;
5656
}
5757
})();

0 commit comments

Comments
 (0)