Skip to content

Function: createRouter()

API / @xmachines/play-dom-router / createRouter

function createRouter(options): VanillaRouter;

Defined in: play-dom-router/src/create-router.ts:52

Create vanilla router for framework-agnostic routing.

Architecture:

  • Just wraps history and routeTree
  • Does NOT embed routeMap (providers need it as prop)
  • Framework-agnostic history management only

Why no routeMap:

  • Router doesn’t know about state IDs (that’s Play-specific)
  • RouteMap is the bridge between router and actor
  • Provider receives routeMap as prop to do path → state ID resolution

Usage (parallel to TanStack mode):

// Both modes: identical setup
const routeTree = extractMachineRoutes(machine);
const routeMap = createRouteMapFromTree(routeTree);
const history = createBrowserHistory({ window });
// Vanilla router
const router = createRouter({ routeTree, history });
// Connect router to actor (handles all bidirectional sync)
const disconnect = connectRouter({ actor, router, routeMap });
// Later: cleanup
disconnect();
router.destroy();

Parameters

ParameterType
options{ history: BrowserHistory; routeTree: RouteTree; }
options.historyBrowserHistory
options.routeTreeRouteTree

Returns

VanillaRouter