( list: RouteObject[] = routes, parentPath = "" )
| 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`. |
| 53 | export 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 | } |
no test coverage detected