Skip to content

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

ParameterTypeDescription
graphGraph<MachineNodeData, MachineEdgeData>The machine graph, from RouteTree.graph
fromStateIdstringThe ID of the state of the origin
toStateIdstringThe 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
}