Skip to content

Commit

Permalink
fix(menu): fix externalLink not work
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Dec 7, 2020
1 parent e921e7b commit 7bae4c3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/router/helper/menuHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { MenuModule, Menu, AppRouteRecordRaw } from '/@/router/types';

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

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

const menuList = [menu];
forEach(menuList, (m) => {
joinParentPath(menuList, m);
!isUrl(m.path) && joinParentPath(menuList, m);
});
return menuList[0];
}
Expand All @@ -58,7 +59,8 @@ export function transformRouteToMenu(routeModList: AppRouteModule[]) {
return treeMap(routeList, {
conversion: (node: AppRouteRecordRaw) => {
const { meta: { title, icon } = {} } = node;
joinParentPath(routeList, node);

!isUrl(node.path) && joinParentPath(routeList, node);
return {
name: title,
icon,
Expand Down
7 changes: 6 additions & 1 deletion src/router/menus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,17 @@ export async function getFlatChildrenMenus(children: Menu[]) {
function basicFilter(routes: RouteRecordNormalized[]) {
return (menu: Menu) => {
const matchRoute = routes.find((route) => {
if (route.meta.externalLink) {
return true;
}

if (route.meta) {
if (route.meta.carryParam) {
return pathToRegexp(route.path).test(menu.path);
}
if (route.meta.ignoreAuth) return false;
if (route.meta.ignoreAuth) return true;
}

return route.path === menu.path;
});

Expand Down
2 changes: 1 addition & 1 deletion src/router/menus/modules/demo/iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const menu: MenuModule = {
name: 'routes.demo.iframe.doc',
},
{
path: 'docExternal',
path: 'https://vvbin.cn/doc-next/',
name: 'routes.demo.iframe.docExternal',
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/router/routes/modules/demo/iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ const iframe: AppRouteModule = {
},
},
{
path: 'docExternal',
path: 'https://vvbin.cn/doc-next/',
name: 'DocExternal',
component: IFrame,
meta: {
externalLink: 'https://vvbin.cn/doc-next/',
externalLink: true,
title: 'routes.demo.iframe.docExternal',
},
},
Expand Down
3 changes: 2 additions & 1 deletion src/router/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface RouteMeta {
// Jump address
frameSrc?: string;
// Outer link jump address
externalLink?: string;
externalLink?: boolean;

// current page transition
transitionName?: string;
Expand All @@ -28,6 +28,7 @@ export interface RouteMeta {
// Carrying parameters
carryParam?: boolean;

// Used internally to mark single-level menus
single?: boolean;
}

Expand Down

0 comments on commit 7bae4c3

Please sign in to comment.