Function: createRouteMap()
Documentation / @xmachines/play-router / createRouteMap
function createRouteMap(routeTree): RouteMap;Defined in: create-route-map.ts:120
Create a RouteMap from a RouteTree for efficient path lookups.
Architecture:
- Pure function - no side effects
- O(1) lookups for exact matches via Map
- O(k) bucket-indexed pattern matching with URLPattern, where k = routes in the first-segment bucket (typically << total routes)
- Returns formatted state IDs (with # prefix)
- Extracts params from matched patterns
URLPattern requirement: Dynamic route pattern matching requires URLPattern
to be available on globalThis. On Node.js < 24 and older browsers, load a polyfill
before calling this function:
import "urlpattern-polyfill"; // before importing @xmachines/play-routerIf URLPattern is unavailable, parameterized routes will not match and a
console.warn is emitted. Static (exact) routes are unaffected.
Usage:
const routeTree = extractMachineRoutes(machine);const routeMap = createRouteMap(routeTree);
const { to, params } = routeMap.resolve("/settings/account");if (to) { actor.send({ type: "play.route", to, params });}Parameters
| Parameter | Type |
|---|---|
routeTree | RouteTree |