Files
schoolNews/schoolNewsWeb/src/utils/routeUtils.ts

19 lines
658 B
TypeScript
Raw Normal View History

2025-10-18 18:19:19 +08:00
import { RouteRecordRaw, RouteLocationNormalized } from 'vue-router';
export function getParentChildrenRoutes(route: RouteLocationNormalized): RouteRecordRaw[] {
// 判断是否有父节点至少需要2个匹配的路由
if (route.matched.length < 2) {
return [];
}
// 获取倒数第二个匹配的路由(父路由)
const parentRoute = route.matched[route.matched.length - 2];
// 检查父路由是否有子路由
if (!parentRoute?.children || parentRoute.children.length === 0) {
return [];
}
// 返回有 title 的子路由
return parentRoute.children.filter((child: RouteRecordRaw) => child.meta?.title);
}