Skip to content

Commit 7bae4c3

Browse files
committed
fix(menu): fix externalLink not work
1 parent e921e7b commit 7bae4c3

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

src/router/helper/menuHelper.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { MenuModule, Menu, AppRouteRecordRaw } from '/@/router/types';
33

44
import { findPath, forEach, treeMap, treeToList } from '/@/utils/helper/treeHelper';
55
import { cloneDeep } from 'lodash-es';
6+
import { isUrl } from '/@/utils/is';
67

78
export function getAllParentPath(treeData: any[], path: string) {
89
const menuList = findPath(treeData, (n) => n.path === path) as Menu[];
@@ -39,7 +40,7 @@ export function transformMenuModule(menuModule: MenuModule): Menu {
3940

4041
const menuList = [menu];
4142
forEach(menuList, (m) => {
42-
joinParentPath(menuList, m);
43+
!isUrl(m.path) && joinParentPath(menuList, m);
4344
});
4445
return menuList[0];
4546
}
@@ -58,7 +59,8 @@ export function transformRouteToMenu(routeModList: AppRouteModule[]) {
5859
return treeMap(routeList, {
5960
conversion: (node: AppRouteRecordRaw) => {
6061
const { meta: { title, icon } = {} } = node;
61-
joinParentPath(routeList, node);
62+
63+
!isUrl(node.path) && joinParentPath(routeList, node);
6264
return {
6365
name: title,
6466
icon,

src/router/menus/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,17 @@ export async function getFlatChildrenMenus(children: Menu[]) {
8989
function basicFilter(routes: RouteRecordNormalized[]) {
9090
return (menu: Menu) => {
9191
const matchRoute = routes.find((route) => {
92+
if (route.meta.externalLink) {
93+
return true;
94+
}
95+
9296
if (route.meta) {
9397
if (route.meta.carryParam) {
9498
return pathToRegexp(route.path).test(menu.path);
9599
}
96-
if (route.meta.ignoreAuth) return false;
100+
if (route.meta.ignoreAuth) return true;
97101
}
102+
98103
return route.path === menu.path;
99104
});
100105

src/router/menus/modules/demo/iframe.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const menu: MenuModule = {
1515
name: 'routes.demo.iframe.doc',
1616
},
1717
{
18-
path: 'docExternal',
18+
path: 'https://vvbin.cn/doc-next/',
1919
name: 'routes.demo.iframe.docExternal',
2020
},
2121
],

src/router/routes/modules/demo/iframe.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ const iframe: AppRouteModule = {
3333
},
3434
},
3535
{
36-
path: 'docExternal',
36+
path: 'https://vvbin.cn/doc-next/',
3737
name: 'DocExternal',
3838
component: IFrame,
3939
meta: {
40-
externalLink: 'https://vvbin.cn/doc-next/',
40+
externalLink: true,
4141
title: 'routes.demo.iframe.docExternal',
4242
},
4343
},

src/router/types.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface RouteMeta {
1717
// Jump address
1818
frameSrc?: string;
1919
// Outer link jump address
20-
externalLink?: string;
20+
externalLink?: boolean;
2121

2222
// current page transition
2323
transitionName?: string;
@@ -28,6 +28,7 @@ export interface RouteMeta {
2828
// Carrying parameters
2929
carryParam?: boolean;
3030

31+
// Used internally to mark single-level menus
3132
single?: boolean;
3233
}
3334

0 commit comments

Comments
 (0)