Skip to content

Commit 56347b4

Browse files
committed
optimize the recursive routes call
1 parent ce1c7a0 commit 56347b4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/client/utils/sanitize.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,17 @@ interface RawNodeDatum {
5252
children?: RawNodeDatum[]
5353
errorBoundary: { hasErrorBoundary: boolean; errorBoundaryId: string | null }
5454
}
55-
55+
const routeMap = new Map()
5656
const constructTree = (routes: any, parentId?: string): RawNodeDatum[] => {
5757
const nodes: RawNodeDatum[] = []
5858
const routeKeys = Object.keys(routes)
5959
for (const key of routeKeys) {
6060
const route = routes[key]
6161
if (route.parentId === parentId) {
62+
if (routeMap.get(key)) {
63+
nodes.push(routeMap.get(key))
64+
return nodes
65+
}
6266
const url = convertReactRouterPathToUrl(routes, route)
6367
const node: RawNodeDatum = {
6468
name: url,
@@ -69,6 +73,7 @@ const constructTree = (routes: any, parentId?: string): RawNodeDatum[] => {
6973
errorBoundary: findParentErrorBoundary(route),
7074
children: constructTree(routes, route.id),
7175
}
76+
routeMap.set(key, node)
7277
nodes.push(node)
7378
}
7479
}

0 commit comments

Comments
 (0)