fix: 修复构建报错
This commit is contained in:
@@ -1,7 +1,14 @@
|
|||||||
// src/components/menu/MenuContent.tsx
|
// src/components/menu/MenuContent.tsx
|
||||||
import { defineComponent, ref, h, compile, computed } from 'vue';
|
import { defineComponent, ref, h, compile, computed } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRoute, useRouter, RouteRecordRaw } from 'vue-router';
|
import {
|
||||||
|
useRoute,
|
||||||
|
useRouter,
|
||||||
|
RouteRecordRaw,
|
||||||
|
RouteLocationNormalized,
|
||||||
|
RouteLocationAsPathGeneric,
|
||||||
|
RouteLocationAsRelativeGeneric,
|
||||||
|
} from 'vue-router';
|
||||||
import type { RouteMeta } from 'vue-router';
|
import type { RouteMeta } from 'vue-router';
|
||||||
import { useAppStore } from '@/store';
|
import { useAppStore } from '@/store';
|
||||||
import { listenerRouteChange } from '@/utils/route-listener';
|
import { listenerRouteChange } from '@/utils/route-listener';
|
||||||
@@ -36,8 +43,29 @@ export default defineComponent({
|
|||||||
selectedKey.value = [item.name as string];
|
selectedKey.value = [item.name as string];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// if (item.redirect) {
|
||||||
|
// router.push(item.redirect);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
if (item.redirect) {
|
if (item.redirect) {
|
||||||
router.push(item.redirect);
|
// 1. 定义 redirect 结果的类型(匹配 router.push 接受的参数类型)
|
||||||
|
let redirectTarget:
|
||||||
|
| string
|
||||||
|
| RouteLocationAsRelativeGeneric
|
||||||
|
| RouteLocationAsPathGeneric;
|
||||||
|
|
||||||
|
// 2. 判断 redirect 是否为函数(动态重定向)
|
||||||
|
if (typeof item.redirect === 'function') {
|
||||||
|
// 执行函数:需要传入当前路由对象(route 是 useRoute() 获取的当前路由)
|
||||||
|
// RouteLocationNormalized 是当前路由的完整类型
|
||||||
|
redirectTarget = item.redirect(route as RouteLocationNormalized);
|
||||||
|
} else {
|
||||||
|
// 静态重定向:直接使用 redirect 值(字符串/对象)
|
||||||
|
redirectTarget = item.redirect;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 执行重定向(此时 redirectTarget 类型完全匹配 router.push 要求)
|
||||||
|
router.push(redirectTarget);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { hideInMenu, activeMenu } = item.meta as RouteMeta;
|
const { hideInMenu, activeMenu } = item.meta as RouteMeta;
|
||||||
|
|||||||
Reference in New Issue
Block a user