Skip to content

Function: extractRoute()

Documentation / @xmachines/play-router / extractRoute

function extractRoute(node, path, stateMap): RouteInfo | null;

Defined in: extract-route.ts:26

Extract route information from state node with validation

States with meta.route are “routable” - they can receive play.route events (when machine is wrapped with formatPlayRouteTransitions).

Parameters

ParameterTypeDescription
nodeStateNodeXState StateNode to extract route from
pathstring[]State path segments from root
stateMapMap<string, StateNode<MachineContext, EventObject>>Map of all state IDs to StateNodes for validation

Returns

RouteInfo | null

RouteInfo if state has meta.route, null otherwise

Throws

If route path is malformed (missing leading /)

Throws

If route references non-existent state

Example

const node = {
id: "dashboard",
meta: { route: "/dashboard" },
};