Commit e0dc5cf2f299fd4c1efdf4f00b9f0f72f07d5937
1 parent
d5d4c4b4
fix(breadcrumb): ensure that the single-level breadcrumbs jump correctly close #321
Showing
3 changed files
with
38 additions
and
16 deletions
CHANGELOG.zh_CN.md
src/layouts/default/header/components/Breadcrumb.vue
... | ... | @@ -72,10 +72,25 @@ |
72 | 72 | if (currentRoute.value.meta?.currentActiveMenu) { |
73 | 73 | filterBreadcrumbList.push((currentRoute.value as unknown) as RouteLocationMatched); |
74 | 74 | } |
75 | - // routes.value = filterBreadcrumbList.length === 1 ? [] : filterBreadcrumbList; | |
76 | - routes.value = filterBreadcrumbList; | |
75 | + routes.value = subRouteExtraction(filterBreadcrumbList); | |
77 | 76 | }); |
78 | 77 | |
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 | + | |
79 | 94 | function filterItem(list: RouteLocationMatched[]) { |
80 | 95 | let resultList = filter(list, (item) => { |
81 | 96 | const { meta } = item; |
... | ... | @@ -83,15 +98,14 @@ |
83 | 98 | if (!meta) { |
84 | 99 | return false; |
85 | 100 | } |
101 | + | |
86 | 102 | const { title, hideBreadcrumb, hideMenu } = meta; |
87 | 103 | if (!title || hideBreadcrumb || hideMenu) { |
88 | 104 | return false; |
89 | 105 | } |
90 | - | |
91 | 106 | return true; |
92 | 107 | }).filter((item) => !item.meta?.hideBreadcrumb || !item.meta?.hideMenu); |
93 | 108 | |
94 | - // resultList = resultList.filter((item) => item.path !== PageEnum.BASE_HOME); | |
95 | 109 | return resultList; |
96 | 110 | } |
97 | 111 | |
... | ... | @@ -101,7 +115,8 @@ |
101 | 115 | children, |
102 | 116 | redirect, |
103 | 117 | meta, |
104 | - // components | |
118 | + | |
119 | + // components | |
105 | 120 | } = route; |
106 | 121 | |
107 | 122 | // const isParent = |
... | ... | @@ -123,23 +138,29 @@ |
123 | 138 | if (redirect && isString(redirect)) { |
124 | 139 | go(redirect); |
125 | 140 | } 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); | |
132 | 152 | } |
133 | 153 | } |
134 | 154 | |
135 | 155 | function hasRedirect(routes: RouteLocationMatched[], route: RouteLocationMatched) { |
136 | - if (route?.meta?.isLink) { | |
137 | - return true; | |
138 | - } | |
139 | - | |
140 | 156 | if (routes.indexOf(route) === routes.length - 1) { |
141 | 157 | return false; |
142 | 158 | } |
159 | + | |
160 | + // if (route?.meta?.isLink) { | |
161 | + // return true; | |
162 | + // } | |
163 | + | |
143 | 164 | return true; |
144 | 165 | } |
145 | 166 | ... | ... |
src/main.ts