Function: createRouteMap()
API / @xmachines/play-router / xstate / createRouteMap
function createRouteMap(machine, options?): RouteMap;Defined in: packages/play-router/src/xstate/create-route-map.ts:32
Creates a RouteMap from an XState state machine.
The function reads every state with a route, which means each state with a
meta.route field. It keeps the routable states alone, and it drops the synthetic
root of the tree. createRouteMapFromTree of the main entry point drops the same
node, and the two functions therefore answer the same map for the same machine. It then builds the lookup structure between a path and a
stateId, for both directions. A subclass of RouterBridgeBase uses the map: it
converts each change of the browser URL into a play.route actor event, and each
actor route into a URL.
Parameters
| Parameter | Type | Description |
|---|---|---|
machine | AnyStateMachine | The XState v5 state machine, with a meta.route annotation on each state with a route. |
options? | RouteMapOptions | The optional configuration. Give { pathCache } to replace the default LRU cache of the parameterized path lookups with one that you own. |
Returns
A RouteMap for each adapter on RouterBridgeBase.
Example
import { createRouteMap } from "@xmachines/play-router/xstate";import { connectRouter } from "@xmachines/play-dom-router";
const routeMap = createRouteMap(myMachine);const disconnect = connectRouter({ actor, router, routeMap });