Function: formatPlayRouteTransitions()
Documentation / @xmachines/play-xstate / formatPlayRouteTransitions
function formatPlayRouteTransitions<T>(machineConfig): T;Defined in: packages/play-xstate/src/routing/format-play-route-transitions.ts:65
Formats play.route transitions from declarative route configs
Crawls machine states looking for states with meta.route and generates
transitions that handle play.route events by matching event.to to state IDs.
Inspired by XState’s internal formatRouteTransitions (stateUtils.ts line 391).
Type Parameters
| Type Parameter |
|---|
T extends RouteMachineConfig |
Parameters
| Parameter | Type | Description |
|---|---|---|
machineConfig | T | XState machine config (before createMachine). Must extend RouteMachineConfig. |
Returns
T
The same machine config with auto-generated play.route handlers merged in, preserving the original type T.
Example
const machineConfig = { id: "myMachine", states: { home: { id: "home", meta: { route: "/home" } }, dashboard: { id: "dashboard", meta: { route: "/dashboard" } }, },};
const machine = createMachine(formatPlayRouteTransitions(machineConfig));This automatically generates play.route handlers at the root level that:
- Match event.to against state IDs (e.g., event.to === “#home”)
- Target the appropriate state
- Assign routeParams and queryParams from the event to context