MCPcopy Create free account
hub / github.com/bytebase/bytebase / buildRouteNameIndex

Function buildRouteNameIndex

frontend/src/react/router/routes.tsx:53–77  ·  view source on GitHub ↗
(
  list: RouteObject[] = routes,
  parentPath = ""
)

Source from the content-addressed store, hash-verified

51// the ported guard + auth lifecycle can resolve their by-name redirects to
52// paths. Lives here (a `.tsx` module) so `navigation.ts` stays a pure `.ts`.
53export function buildRouteNameIndex(
54 list: RouteObject[] = routes,
55 parentPath = ""
56): Map<string, string> {
57 const index = new Map<string, string>();
58 for (const route of list) {
59 const segment = route.path ?? "";
60 const fullPath = route.path?.startsWith("/")
61 ? segment
62 : joinPath(parentPath, segment);
63 const name = (route.handle as { name?: string } | undefined)?.name;
64 if (name && !index.has(name)) {
65 index.set(name, fullPath || "/");
66 }
67 if (route.children) {
68 for (const [childName, childPath] of buildRouteNameIndex(
69 route.children,
70 fullPath
71 )) {
72 if (!index.has(childName)) index.set(childName, childPath);
73 }
74 }
75 }
76 return index;
77}

Callers 1

AppRoot.tsxFile · 0.90

Calls 2

joinPathFunction · 0.70
setMethod · 0.45

Tested by

no test coverage detected