Skip to content

Function: extractMachineRoutes()

API / @xmachines/play-router / extractMachineRoutes

function extractMachineRoutes(machine): RouteTree;

Defined in: extract-routes.ts:92

Reads the complete route tree from the graph of a state machine

The function converts the XState machine into a Graph of @statelyai/graph, with machineToGraph(). It then walks the graph nodes: it reads the route metadata of each node, it checks each route reference, and it builds a hierarchical RouteTree. The RouteTree of the return value also holds the graph, for a later query that needs the transitions.

Parameters

ParameterTypeDescription
machineAnyStateMachineThe XState v5 state machine

Returns

RouteTree

The route tree, with its root, its byStateId map, its byPath map, and its graph