Commit f5e31febbd18372a34166cac390b1d9b914fe80e
1 parent
6f830703
fix(breadcrumb): `redirect` not worked
修复面包屑组件的重定向菜单不能工作以及eslint警告
Showing
2 changed files
with
6 additions
and
10 deletions
src/layouts/default/header/components/Breadcrumb.vue
1 | 1 | <template> |
2 | 2 | <div :class="[prefixCls, `${prefixCls}--${theme}`]"> |
3 | 3 | <a-breadcrumb :routes="routes"> |
4 | - <template #itemRender="{ route, routes, paths }"> | |
4 | + <template #itemRender="{ route, routes: routesMatched, paths }"> | |
5 | 5 | <Icon :icon="getIcon(route)" v-if="getShowBreadCrumbIcon && getIcon(route)" /> |
6 | - <span v-if="!hasRedirect(routes, route)"> | |
6 | + <span v-if="!hasRedirect(routesMatched, route)"> | |
7 | 7 | {{ t(route.name || route.meta.title) }} |
8 | 8 | </span> |
9 | 9 | <router-link v-else to="" @click="handleClick(route, paths, $event)"> |
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | </template> |
16 | 16 | <script lang="ts"> |
17 | 17 | import type { RouteLocationMatched } from 'vue-router'; |
18 | + import { useRouter } from 'vue-router'; | |
18 | 19 | import type { Menu } from '/@/router/types'; |
19 | 20 | |
20 | 21 | import { defineComponent, ref, watchEffect } from 'vue'; |
... | ... | @@ -26,7 +27,6 @@ |
26 | 27 | import { useRootSetting } from '/@/hooks/setting/useRootSetting'; |
27 | 28 | import { useGo } from '/@/hooks/web/usePage'; |
28 | 29 | import { useI18n } from '/@/hooks/web/useI18n'; |
29 | - import { useRouter } from 'vue-router'; | |
30 | 30 | |
31 | 31 | import { propTypes } from '/@/utils/propTypes'; |
32 | 32 | import { isString } from '/@/utils/is'; |
... | ... | @@ -96,7 +96,7 @@ |
96 | 96 | } |
97 | 97 | |
98 | 98 | function filterItem(list: RouteLocationMatched[]) { |
99 | - let resultList = filter(list, (item) => { | |
99 | + return filter(list, (item) => { | |
100 | 100 | const { meta, name } = item; |
101 | 101 | if (!meta) { |
102 | 102 | return !!name; |
... | ... | @@ -107,8 +107,6 @@ |
107 | 107 | } |
108 | 108 | return true; |
109 | 109 | }).filter((item) => !item.meta?.hideBreadcrumb || !item.meta?.hideMenu); |
110 | - | |
111 | - return resultList; | |
112 | 110 | } |
113 | 111 | |
114 | 112 | function handleClick(route: RouteLocationMatched, paths: string[], e: Event) { |
... | ... | @@ -140,10 +138,7 @@ |
140 | 138 | } |
141 | 139 | |
142 | 140 | function hasRedirect(routes: RouteLocationMatched[], route: RouteLocationMatched) { |
143 | - if (routes.indexOf(route) === routes.length - 1) { | |
144 | - return false; | |
145 | - } | |
146 | - return true; | |
141 | + return routes.indexOf(route) !== routes.length - 1; | |
147 | 142 | } |
148 | 143 | |
149 | 144 | function getIcon(route) { | ... | ... |
src/router/helper/menuHelper.ts