Function: createRouteMapFromTree()
API / @xmachines/play-router / createRouteMapFromTree
function createRouteMapFromTree(routeTree, options?): RouteMap;Defined in: create-route-map-from-tree.ts:33
Create a RouteMap from a RouteTree node structure.
Used by framework-router adapters (React Router, TanStack Router) that pass a
RouteTree produced by extractMachineRoutes() rather than calling
createRouteMap() directly.
Traverses all nodes collecting { stateId: node.id, path: node.fullPath } pairs.
node.fullPath is always the absolute resolved path (e.g. "/dashboard/overview"),
which is what RouteMap needs for browser URL matching. This matches the
behaviour of createRouteMap(machine), which also uses node.fullPath.
Parameters
| Parameter | Type | Description |
|---|---|---|
routeTree | RouteTree | A RouteTree as returned by extractMachineRoutes(). |
options? | RouteMapOptions | Optional configuration (e.g. { cacheSize } to override the LRU cache size). |
Returns
A RouteMap for use with any RouterBridgeBase-based adapter.
Example
// Preferred — single call for XState machines:import { createRouteMap } from "@xmachines/play-router";const routeMap = createRouteMap(machine); // takes AnyStateMachine
// Two-step form used by framework adapters that work with route trees:import { extractMachineRoutes, createRouteMapFromTree } from "@xmachines/play-router";const routeTree = extractMachineRoutes(machine);const routeMap = createRouteMapFromTree(routeTree); // uses node.fullPath (absolute)