Skip to content

Function: findRouteById()

API / @xmachines/play-router / findRouteById

function findRouteById(tree, id): RouteNode | undefined;

Defined in: find-route.ts:59

Finds a route node by its state ID

The function looks the route node up by the ID property of the state. It gives you the URL path of a state ID, for the update of the browser URL after a play.route transition.

Parameters

ParameterTypeDescription
treeRouteTreeThe route tree, from extractMachineRoutes
idstringThe state ID, for example ‘dashboard’ or ‘settings.profile’

Returns

RouteNode | undefined

The route node, or undefined when the function finds none

Example

const tree = extractMachineRoutes(machine);
const node = findRouteById(tree, "dashboard");
if (node) {
console.log(node.fullPath); // '/dashboard'
}