Function: isRouteReachable()
API / @xmachines/play-router / isRouteReachable
function isRouteReachable(graph, fromStateId, toStateId): boolean;Defined in: query.ts:186
Tells you if a transition from the current state can reach a route
The function uses the path search of @statelyai/graph. It decides if a chain of transition edges is present from the state of the origin to the state of the target.
Parameters
| Parameter | Type | Description |
|---|---|---|
graph | Graph<MachineNodeData, MachineEdgeData> | The machine graph, from RouteTree.graph |
fromStateId | string | The ID of the state of the origin |
toStateId | string | The ID of the state of the target |
Returns
boolean
true when a transition path is present. In every other case, false
Example
const tree = extractMachineRoutes(machine);if (tree.graph) { const canReach = isRouteReachable(tree.graph, "auth.login", "auth.dashboard"); // it is true when a transition path from login to dashboard is present}