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 | <template> | 1 | <template> |
2 | <div :class="[prefixCls, `${prefixCls}--${theme}`]"> | 2 | <div :class="[prefixCls, `${prefixCls}--${theme}`]"> |
3 | <a-breadcrumb :routes="routes"> | 3 | <a-breadcrumb :routes="routes"> |
4 | - <template #itemRender="{ route, routes, paths }"> | 4 | + <template #itemRender="{ route, routes: routesMatched, paths }"> |
5 | <Icon :icon="getIcon(route)" v-if="getShowBreadCrumbIcon && getIcon(route)" /> | 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 | {{ t(route.name || route.meta.title) }} | 7 | {{ t(route.name || route.meta.title) }} |
8 | </span> | 8 | </span> |
9 | <router-link v-else to="" @click="handleClick(route, paths, $event)"> | 9 | <router-link v-else to="" @click="handleClick(route, paths, $event)"> |
@@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
15 | </template> | 15 | </template> |
16 | <script lang="ts"> | 16 | <script lang="ts"> |
17 | import type { RouteLocationMatched } from 'vue-router'; | 17 | import type { RouteLocationMatched } from 'vue-router'; |
18 | + import { useRouter } from 'vue-router'; | ||
18 | import type { Menu } from '/@/router/types'; | 19 | import type { Menu } from '/@/router/types'; |
19 | 20 | ||
20 | import { defineComponent, ref, watchEffect } from 'vue'; | 21 | import { defineComponent, ref, watchEffect } from 'vue'; |
@@ -26,7 +27,6 @@ | @@ -26,7 +27,6 @@ | ||
26 | import { useRootSetting } from '/@/hooks/setting/useRootSetting'; | 27 | import { useRootSetting } from '/@/hooks/setting/useRootSetting'; |
27 | import { useGo } from '/@/hooks/web/usePage'; | 28 | import { useGo } from '/@/hooks/web/usePage'; |
28 | import { useI18n } from '/@/hooks/web/useI18n'; | 29 | import { useI18n } from '/@/hooks/web/useI18n'; |
29 | - import { useRouter } from 'vue-router'; | ||
30 | 30 | ||
31 | import { propTypes } from '/@/utils/propTypes'; | 31 | import { propTypes } from '/@/utils/propTypes'; |
32 | import { isString } from '/@/utils/is'; | 32 | import { isString } from '/@/utils/is'; |
@@ -96,7 +96,7 @@ | @@ -96,7 +96,7 @@ | ||
96 | } | 96 | } |
97 | 97 | ||
98 | function filterItem(list: RouteLocationMatched[]) { | 98 | function filterItem(list: RouteLocationMatched[]) { |
99 | - let resultList = filter(list, (item) => { | 99 | + return filter(list, (item) => { |
100 | const { meta, name } = item; | 100 | const { meta, name } = item; |
101 | if (!meta) { | 101 | if (!meta) { |
102 | return !!name; | 102 | return !!name; |
@@ -107,8 +107,6 @@ | @@ -107,8 +107,6 @@ | ||
107 | } | 107 | } |
108 | return true; | 108 | return true; |
109 | }).filter((item) => !item.meta?.hideBreadcrumb || !item.meta?.hideMenu); | 109 | }).filter((item) => !item.meta?.hideBreadcrumb || !item.meta?.hideMenu); |
110 | - | ||
111 | - return resultList; | ||
112 | } | 110 | } |
113 | 111 | ||
114 | function handleClick(route: RouteLocationMatched, paths: string[], e: Event) { | 112 | function handleClick(route: RouteLocationMatched, paths: string[], e: Event) { |
@@ -140,10 +138,7 @@ | @@ -140,10 +138,7 @@ | ||
140 | } | 138 | } |
141 | 139 | ||
142 | function hasRedirect(routes: RouteLocationMatched[], route: RouteLocationMatched) { | 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 | function getIcon(route) { | 144 | function getIcon(route) { |
src/router/helper/menuHelper.ts
@@ -62,6 +62,7 @@ export function transformRouteToMenu(routeModList: AppRouteModule[], routerMappi | @@ -62,6 +62,7 @@ export function transformRouteToMenu(routeModList: AppRouteModule[], routerMappi | ||
62 | name: title, | 62 | name: title, |
63 | hideMenu, | 63 | hideMenu, |
64 | path: node.path, | 64 | path: node.path, |
65 | + ...(node.redirect ? { redirect: node.redirect } : {}), | ||
65 | }; | 66 | }; |
66 | }, | 67 | }, |
67 | }); | 68 | }); |