Function: findRouteByPath()
API / @xmachines/play-router / findRouteByPath
function findRouteByPath(tree, path): RouteNode | undefined;Defined in: find-route.ts:86
Finds a route node by its URL path
The function looks the route node up by the URL path. It gives you the state ID of
a browser URL, for the play.route event of a navigation.
When more than one state holds the same path, for example the root and a second
state both at ”/”, the function prefers a node with a route, which means a node
with a meta.route field, over a node without one.
The function also matches a pattern of a dynamic route, for example ‘/settings/:section?’.
Parameters
| Parameter | Type | Description |
|---|---|---|
tree | RouteTree | The route tree, from extractMachineRoutes |
path | string | The URL path, 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 = findRouteByPath(tree, "/dashboard");