hcifootprintFunctions
fromReactRouter
Function: fromReactRouter()
fromReactRouter(
routes,opts?):RoutesSource
Defined in: src/graph/sources/from-react-router.ts:193
Read a router's own route tree into a RoutesSource — a frozen snapshot of the app's truth, pages only.
THE DERIVATION, exactly (and it is the whole contract):
- ADDRESSES COMPOSE THROUGH CHILDREN. A child's
pathextends its parent's address, unless it starts with '/' — which every router reads as absolute, so it REPLACES the inherited prefix rather than doubling it. The composed address is stored canonically ('/projects/new'), which is whatmatchRouteand the merge read it back as. - A LAYOUT ROUTE IS NOT A PLACE. A route with no
pathof its own (and not an index route) contributes NO page; it only passes its parent's address down to its children. Declaringhandle.hcifootprinton one is refused — a page is an address, and a layout has none of its own. - INDEX ROUTES FOLD INTO THEIR PARENT.
index: truemeans "renders at my parent's address", so it contributes that same address — and two routes at ONE address are ONE page (path: ''folds identically, the other spelling of the same idea). The fold combines their declarations; two folded routes declaring DIFFERENT names refuse, because that is one place with two names. - THE NAME.
nameOffirst (it is the call-site override), thenhandle.hcifootprint.name(a literal on the route the app owns), then the TRANSCRIPTION — the address's segments joined with '-', so '/' + no segments and any dynamic segment are exactly the cases that cannot be transcribed and refuse instead, naming the path and both doors. - NAMES ARE UNIQUE. Two different addresses arriving at one page id refuse, naming both paths. Never last-wins: a silently-swallowed page is a place an agent can never be told about.
Parameters
routes
readonly RouteObjectLike[]
opts?
Returns
Example
const source = fromReactRouter(app.routes, {
nameOf: (route, path) => (path === '/' ? 'home' : undefined),
});