web-权限、文章
This commit is contained in:
21
schoolNewsWeb/src/utils/routeUtils.ts
Normal file
21
schoolNewsWeb/src/utils/routeUtils.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { RouteRecordRaw, RouteLocationNormalized } from 'vue-router';
|
||||
|
||||
export function getParentChildrenRoutes(route: RouteLocationNormalized): RouteRecordRaw[] {
|
||||
// 判断是否有父节点(至少需要2个匹配的路由)
|
||||
if (route.matched.length < 2) {
|
||||
console.log('没有父节点,route.matched 长度不足');
|
||||
return [];
|
||||
}
|
||||
|
||||
// 获取倒数第二个匹配的路由(父路由)
|
||||
const parentRoute = route.matched[route.matched.length - 2];
|
||||
|
||||
// 检查父路由是否有子路由
|
||||
if (!parentRoute?.children || parentRoute.children.length === 0) {
|
||||
console.log('父路由没有子路由');
|
||||
return [];
|
||||
}
|
||||
|
||||
// 返回有 title 的子路由
|
||||
return parentRoute.children.filter((child: RouteRecordRaw) => child.meta?.title);
|
||||
}
|
||||
Reference in New Issue
Block a user