Skip to content

Function: createRouteMap()

API / @xmachines/play-react-router / createRouteMap

function createRouteMap(machine, options?): RouteMap;

Defined in: play-router/src/create-route-map.ts:45

Create a RouteMap from an XState state machine.

Extracts all routable states (those with meta.route) and builds a bidirectional path ↔ stateId lookup structure. The returned map is used by RouterBridgeBase subclasses to translate browser URL changes into play.route actor events and vice-versa.

Parameters

ParameterTypeDescription
machineAnyStateMachineXState v5 state machine with meta.route annotations on states.
options?RouteMapOptionsOptional configuration. Pass { cacheSize } to override the default LRU cache size for parameterized path lookups.

Returns

RouteMap

A RouteMap for passing to any RouterBridgeBase-based adapter.

Example

import { createRouteMap } from "@xmachines/play-router";
import { connectRouter } from "@xmachines/play-dom-router";
const routeMap = createRouteMap(myMachine);
const disconnect = connectRouter({ actor, router, routeMap });