Commit 7bae4c37525c6534ec0b0c3ea8c1b2257af74a33

Authored by vben
1 parent e921e7b9

fix(menu): fix externalLink not work

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