Skip to content

Commit dbc0b7e

Browse files
anyupanyup
and
anyup
authored
fix: route root.children duplicate problem (#5755)
Co-authored-by: anyup <[email protected]>
1 parent aa29073 commit dbc0b7e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/effects/access/src/accessible.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ async function generateAccessible(
3030

3131
const root = router.getRoutes().find((item) => item.path === '/');
3232

33+
// 获取已有的路由名称列表
34+
const names = root?.children?.map((item) => item.name) ?? [];
35+
3336
// 动态添加到router实例内
3437
accessibleRoutes.forEach((route) => {
3538
if (root && !route.meta?.noBasicLayout) {
@@ -38,7 +41,10 @@ async function generateAccessible(
3841
if (route.children && route.children.length > 0) {
3942
delete route.component;
4043
}
41-
root.children?.push(route);
44+
// 根据router name判断,如果路由已经存在,则不再添加
45+
if (!names?.includes(route.name)) {
46+
root.children?.push(route);
47+
}
4248
} else {
4349
router.addRoute(route);
4450
}

0 commit comments

Comments
 (0)