Skip to content

Function: connectRouter()

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

function connectRouter(options): RouterConnection;

Defined in: play-dom-router/src/connect-router.ts:64

Connects the vanilla router to an actor. This is a pure browser integration.

The function returns a CALLABLE handle: call it to stop the synchronization, as before. The handle also carries the mount — basePath, basePathParams and setBasePath() — because the bridge itself stays inside this function.

Parameters

ParameterType
optionsConnectRouterOptions

Returns

RouterConnection

Example

import { createBrowserHistory, createRouter, connectRouter } from "@xmachines/play-dom-router";
import { createRouteMap, extractMachineRoutes } from "@xmachines/play-router/xstate";
const routeTree = extractMachineRoutes(machine);
const routeMap = createRouteMap(machine);
const history = createBrowserHistory({ window });
const router = createRouter({ routeTree, history });
const disconnect = connectRouter({ actor, router, routeMap });
// Later:
disconnect();