Skip to content

Commit be9b1c9

Browse files
committed
fix: target link no high in menu
1 parent 17ee236 commit be9b1c9

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

examples/router.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ const routes: RouteRecordRaw[] = [
6565
meta: { title: 'Single', icon: 'SettingOutlined' },
6666
component: () => import('./views/page1.vue'),
6767
},
68+
{
69+
path: 'http://www.baidu.com/',
70+
name: 'baidu_target',
71+
meta: { title: '百度一下', target: '_blank' },
72+
component: null,
73+
},
6874
],
6975
},
7076
];

src/SiderMenu/BaseMenu.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const LazyIcon: FunctionalComponent<{
110110
icon: VNodeChild | string;
111111
iconPrefixes?: string;
112112
prefixCls?: string;
113-
}> = (props) => {
113+
}> = props => {
114114
const { icon, iconPrefixes = 'icon-', prefixCls = 'ant-pro' } = props;
115115
if (!icon) {
116116
return null;
@@ -193,12 +193,13 @@ class MenuUtil {
193193
);
194194
}
195195

196-
const menuItemRender = this.props.menuItemRender && withCtx(this.props.menuItemRender, this.ctx)
196+
const menuItemRender =
197+
this.props.menuItemRender && withCtx(this.props.menuItemRender, this.ctx);
197198

198199
const [title, icon] = this.getMenuItem(item);
199200

200201
return (
201-
(menuItemRender && menuItemRender({ item, title, icon }) as VNode) || (
202+
(menuItemRender && (menuItemRender({ item, title, icon }) as VNode)) || (
202203
<Menu.Item
203204
disabled={item.meta?.disabled}
204205
danger={item.meta?.danger}
@@ -250,41 +251,44 @@ export type MenuOnSelect = {
250251
item: VNodeChild | any;
251252
domEvent: MouseEvent;
252253
selectedKeys: string[];
253-
}
254+
};
254255

255-
export type MenuOnClick={
256+
export type MenuOnClick = {
256257
item: VNodeChild;
257258
key: string | number;
258259
keyPath: string | string[] | number | number[];
259-
}
260+
};
260261

261262
export default defineComponent({
262263
name: 'BaseMenu',
263264
props: baseMenuProps,
264265
emits: ['update:openKeys', 'update:selectedKeys', 'click'],
265266
setup(props, { emit }) {
266-
const ctx = getCurrentInstance()
267+
const ctx = getCurrentInstance();
267268
const menuUtil = new MenuUtil(props, ctx);
268269
// update iconfontUrl
269270
watchEffect(() => {
270271
if (props.iconfontUrl) {
271272
IconFont = createFromIconfontCN({
272273
scriptUrl: props.iconfontUrl,
273-
})
274+
});
274275
}
275-
})
276+
});
276277

277278
const handleOpenChange = (openKeys: string[]): void => {
278279
emit('update:openKeys', openKeys);
279280
};
280281
const handleSelect = (args: MenuOnSelect): void => {
282+
// ignore https? link handle selectkeys
283+
if (isUrl(args.key as string)) {
284+
return;
285+
}
281286
emit('update:selectedKeys', args.selectedKeys);
282287
};
283288
const handleClick = (args: MenuOnClick) => {
284289
emit('click', args);
285290
};
286291

287-
288292
return () => {
289293
return (
290294
<Menu
@@ -301,7 +305,7 @@ export default defineComponent({
301305
>
302306
{menuUtil.getNavMenuItems(props.menuData)}
303307
</Menu>
304-
)
308+
);
305309
};
306310
},
307311
});

src/utils/getMenuData.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { RouteRecordRaw } from 'vue-router';
2+
import isUrl from './isUrl';
23

34
export { clearMenuItem, flatMap, getMenuFirstChildren } from './index';
45

@@ -14,6 +15,11 @@ export const formatRelativePath = (
1415
): RouteRecordRaw[] => {
1516
// 计算路由绝对路径
1617
return routes.map(route => {
18+
// startWith : http | https
19+
if (isUrl(route.path)) {
20+
return route;
21+
}
22+
1723
// Note that nested paths that start with / will be treated as a root path.
1824
// This allows you to leverage the component nesting without having to use a nested URL.
1925
// @ref https://router.vuejs.org/guide/essentials/nested-routes.html#nested-routes

0 commit comments

Comments
 (0)