feat: add noBasicLayout in route meta (#5386)

所有菜单数据无需配置component为BasicLayout,它们将会默认使用基础布局,也可以通过meta.noBasicLayout来阻止这一行为
This commit is contained in:
Netfan
2025-01-14 12:12:08 +08:00
committed by GitHub
parent 42e322012c
commit 1ad54561b0
22 changed files with 128 additions and 84 deletions

View File

@@ -97,6 +97,10 @@ interface RouteMeta {
* 菜单可以看到但是访问会被重定向到403
*/
menuVisibleWithForbidden?: boolean;
/**
* 不使用基础布局(仅在顶级生效)
*/
noBasicLayout?: boolean;
/**
* 在新窗口打开
*/

View File

@@ -22,11 +22,29 @@ async function generateAccessible(
// 生成路由
const accessibleRoutes = await generateRoutes(mode, options);
const root = router.getRoutes().find((item) => item.path === '/');
// 动态添加到router实例内
accessibleRoutes.forEach((route) => {
router.addRoute(route);
if (root && !route.meta?.noBasicLayout) {
// 为了兼容之前的版本用法如果包含子路由则将component移除以免出现多层BasicLayout
// 如果你的项目已经跟进了本次修改移除了所有自定义菜单首级的BasicLayout可以将这段if代码删除
if (route.children && route.children.length > 0) {
delete route.component;
}
root.children?.push(route);
} else {
router.addRoute(route);
}
});
if (root) {
if (root.name) {
router.removeRoute(root.name);
}
router.addRoute(root);
}
// 生成菜单
const accessibleMenus = await generateMenus(accessibleRoutes, options.router);