Commit 7bae4c37525c6534ec0b0c3ea8c1b2257af74a33
1 parent
e921e7b9
fix(menu): fix externalLink not work
Showing
5 changed files
with
15 additions
and
7 deletions
src/router/helper/menuHelper.ts
@@ -3,6 +3,7 @@ import type { MenuModule, Menu, AppRouteRecordRaw } from '/@/router/types'; | @@ -3,6 +3,7 @@ import type { MenuModule, Menu, AppRouteRecordRaw } from '/@/router/types'; | ||
3 | 3 | ||
4 | import { findPath, forEach, treeMap, treeToList } from '/@/utils/helper/treeHelper'; | 4 | import { findPath, forEach, treeMap, treeToList } from '/@/utils/helper/treeHelper'; |
5 | import { cloneDeep } from 'lodash-es'; | 5 | import { cloneDeep } from 'lodash-es'; |
6 | +import { isUrl } from '/@/utils/is'; | ||
6 | 7 | ||
7 | export function getAllParentPath(treeData: any[], path: string) { | 8 | export function getAllParentPath(treeData: any[], path: string) { |
8 | const menuList = findPath(treeData, (n) => n.path === path) as Menu[]; | 9 | const menuList = findPath(treeData, (n) => n.path === path) as Menu[]; |
@@ -39,7 +40,7 @@ export function transformMenuModule(menuModule: MenuModule): Menu { | @@ -39,7 +40,7 @@ export function transformMenuModule(menuModule: MenuModule): Menu { | ||
39 | 40 | ||
40 | const menuList = [menu]; | 41 | const menuList = [menu]; |
41 | forEach(menuList, (m) => { | 42 | forEach(menuList, (m) => { |
42 | - joinParentPath(menuList, m); | 43 | + !isUrl(m.path) && joinParentPath(menuList, m); |
43 | }); | 44 | }); |
44 | return menuList[0]; | 45 | return menuList[0]; |
45 | } | 46 | } |
@@ -58,7 +59,8 @@ export function transformRouteToMenu(routeModList: AppRouteModule[]) { | @@ -58,7 +59,8 @@ export function transformRouteToMenu(routeModList: AppRouteModule[]) { | ||
58 | return treeMap(routeList, { | 59 | return treeMap(routeList, { |
59 | conversion: (node: AppRouteRecordRaw) => { | 60 | conversion: (node: AppRouteRecordRaw) => { |
60 | const { meta: { title, icon } = {} } = node; | 61 | const { meta: { title, icon } = {} } = node; |
61 | - joinParentPath(routeList, node); | 62 | + |
63 | + !isUrl(node.path) && joinParentPath(routeList, node); | ||
62 | return { | 64 | return { |
63 | name: title, | 65 | name: title, |
64 | icon, | 66 | icon, |
src/router/menus/index.ts
@@ -89,12 +89,17 @@ export async function getFlatChildrenMenus(children: Menu[]) { | @@ -89,12 +89,17 @@ export async function getFlatChildrenMenus(children: Menu[]) { | ||
89 | function basicFilter(routes: RouteRecordNormalized[]) { | 89 | function basicFilter(routes: RouteRecordNormalized[]) { |
90 | return (menu: Menu) => { | 90 | return (menu: Menu) => { |
91 | const matchRoute = routes.find((route) => { | 91 | const matchRoute = routes.find((route) => { |
92 | + if (route.meta.externalLink) { | ||
93 | + return true; | ||
94 | + } | ||
95 | + | ||
92 | if (route.meta) { | 96 | if (route.meta) { |
93 | if (route.meta.carryParam) { | 97 | if (route.meta.carryParam) { |
94 | return pathToRegexp(route.path).test(menu.path); | 98 | return pathToRegexp(route.path).test(menu.path); |
95 | } | 99 | } |
96 | - if (route.meta.ignoreAuth) return false; | 100 | + if (route.meta.ignoreAuth) return true; |
97 | } | 101 | } |
102 | + | ||
98 | return route.path === menu.path; | 103 | return route.path === menu.path; |
99 | }); | 104 | }); |
100 | 105 |
src/router/menus/modules/demo/iframe.ts
@@ -15,7 +15,7 @@ const menu: MenuModule = { | @@ -15,7 +15,7 @@ const menu: MenuModule = { | ||
15 | name: 'routes.demo.iframe.doc', | 15 | name: 'routes.demo.iframe.doc', |
16 | }, | 16 | }, |
17 | { | 17 | { |
18 | - path: 'docExternal', | 18 | + path: 'https://vvbin.cn/doc-next/', |
19 | name: 'routes.demo.iframe.docExternal', | 19 | name: 'routes.demo.iframe.docExternal', |
20 | }, | 20 | }, |
21 | ], | 21 | ], |
src/router/routes/modules/demo/iframe.ts
@@ -33,11 +33,11 @@ const iframe: AppRouteModule = { | @@ -33,11 +33,11 @@ const iframe: AppRouteModule = { | ||
33 | }, | 33 | }, |
34 | }, | 34 | }, |
35 | { | 35 | { |
36 | - path: 'docExternal', | 36 | + path: 'https://vvbin.cn/doc-next/', |
37 | name: 'DocExternal', | 37 | name: 'DocExternal', |
38 | component: IFrame, | 38 | component: IFrame, |
39 | meta: { | 39 | meta: { |
40 | - externalLink: 'https://vvbin.cn/doc-next/', | 40 | + externalLink: true, |
41 | title: 'routes.demo.iframe.docExternal', | 41 | title: 'routes.demo.iframe.docExternal', |
42 | }, | 42 | }, |
43 | }, | 43 | }, |
src/router/types.d.ts
@@ -17,7 +17,7 @@ export interface RouteMeta { | @@ -17,7 +17,7 @@ export interface RouteMeta { | ||
17 | // Jump address | 17 | // Jump address |
18 | frameSrc?: string; | 18 | frameSrc?: string; |
19 | // Outer link jump address | 19 | // Outer link jump address |
20 | - externalLink?: string; | 20 | + externalLink?: boolean; |
21 | 21 | ||
22 | // current page transition | 22 | // current page transition |
23 | transitionName?: string; | 23 | transitionName?: string; |
@@ -28,6 +28,7 @@ export interface RouteMeta { | @@ -28,6 +28,7 @@ export interface RouteMeta { | ||
28 | // Carrying parameters | 28 | // Carrying parameters |
29 | carryParam?: boolean; | 29 | carryParam?: boolean; |
30 | 30 | ||
31 | + // Used internally to mark single-level menus | ||
31 | single?: boolean; | 32 | single?: boolean; |
32 | } | 33 | } |
33 | 34 |