Browse Source

fix: 修复菜单项外部链接跳转问题

- 引入 isHttpUrl 工具函数用于判断 URL 类型
- 添加 isHttp 计算属性检测父路径是否为 HTTP 链接
- 修改菜单项渲染逻辑,对外部链接直接使用原地址跳转
- 调整 HTML 结构,将链接属性移到正确位置
- 确保内部路由和外部链接都能正常工作
pull/7667/head
lmx 4 days ago
parent
commit
e2fb3602f1
  1. 10
      packages/@core/ui-kit/menu-ui/src/components/menu-item.vue

10
packages/@core/ui-kit/menu-ui/src/components/menu-item.vue

@ -5,6 +5,7 @@ import { computed, onBeforeUnmount, onMounted, reactive, useSlots } from 'vue';
import { useNamespace } from '@vben-core/composables';
import { VbenIcon, VbenTooltip } from '@vben-core/shadcn-ui';
import { isHttpUrl } from '@vben-core/shared/utils';
import qs from 'qs';
@ -33,6 +34,8 @@ const menuIcon = computed(() =>
active.value ? props.activeIcon || props.icon : props.icon,
);
const isHttp = computed(() => isHttpUrl(item.parentPaths.at(-1)));
const isTopLevelMenuItem = computed(
() => parentMenu.value?.type.name === 'Menu',
);
@ -92,8 +95,8 @@ onBeforeUnmount(() => {
(item?.query ? `?${qs.stringify(item?.query)}` : '')
"
>
<a :href="href" @click.prevent.stop="handleClick">
<li
<a
:href="isHttp ? item.parentPaths.at(-1) : href"
:class="[
rootMenu.theme,
b(),
@ -102,8 +105,8 @@ onBeforeUnmount(() => {
is('collapse-show-title', collapseShowTitle),
]"
role="menuitem"
@click.prevent.stop="handleClick"
>
<!-- -->
<VbenTooltip
v-if="showTooltip"
:content-class="[rootMenu.theme]"
@ -130,7 +133,6 @@ onBeforeUnmount(() => {
<slot></slot>
<slot name="title"></slot>
</div>
</li>
</a>
</router-link>
</template>

Loading…
Cancel
Save