Skip to content

Function: getTransitionReachableRoutes()

API / @xmachines/play-router / getTransitionReachableRoutes

function getTransitionReachableRoutes(graph, stateId): string[];

Defined in: query.ts:158

Returns the routes that a transition from the current state can reach

The function uses the successor algorithm of @statelyai/graph. It finds every state of a direct transition edge from the given state, then it keeps the states with a route.

The values of the return are the RAW meta.route strings of the machine. The function does NOT resolve a relative route, for example "detail", to a complete path, and such a value is therefore no key of tree.byPath. For a resolved RouteNode, use getNavigableRoutes: that function resolves each state that the transition reaches through tree.byStateId.

Parameters

ParameterTypeDescription
graphGraph<MachineNodeData, MachineEdgeData>The machine graph, from RouteTree.graph
stateIdstringThe ID of the current state, for example “test.home”

Returns

string[]

The array of the raw route strings that a transition can reach

Example

const tree = extractMachineRoutes(machine);
if (tree.graph) {
const reachable = getTransitionReachableRoutes(tree.graph, "auth.loggedIn");
// ['/dashboard', '/settings'] — the routes that a transition can reach
}