Skip to content

Function: getRoutableRoutes()

API / @xmachines/play-router / getRoutableRoutes

function getRoutableRoutes(tree): RouteNode[];

Defined in: query.ts:106

Returns every route of the tree that has a route, in one flat array

The function returns each route with a meta.route field. It returns no state without a route, and no synthetic root node. Use it to generate a router configuration in a framework adapter dynamically.

Parameters

ParameterTypeDescription
treeRouteTreeThe route tree, from extractMachineRoutes()

Returns

RouteNode[]

The array of the route nodes with a route, with their path and their stateId

Example

const tree = extractMachineRoutes(machine);
const routes = getRoutableRoutes(tree);
// [
// { path: '/', stateId: '#home', ... },
// { path: '/about', stateId: '#about', ... },
// { path: '/profile/:userId', stateId: '#profile', ... }
// ]