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); }