Skip to content

Class: TanStackReactRouterBridge

API / @xmachines/play-tanstack-react-router / TanStackReactRouterBridge

Defined in: play-tanstack-router/src/tanstack-router-bridge-base.ts:102

Shared TanStack Router adapter implementing RouterBridge protocol via RouterBridgeBase

Remarks

Extends RouterBridgeBase to handle all common lifecycle and sync logic; adds the TanStack-specific navigation and subscription methods shared by the React and Solid adapters.

Subscribes to router.history (not router.subscribe(“onBeforeLoad”)) so that back/forward browser navigation (popstate events) are also captured. The router.subscribe(“onBeforeLoad”) approach only works when TanStack’s Transitioner component is mounted (i.e. inside a full ). Since this bridge is used without , we must subscribe to the underlying history object directly — which is exactly what Transitioner does internally: router.history.subscribe(router.load).

Architectural Invariants:

  • INV-02 (Passive Infrastructure): Router reflects actor state, never decides
  • Actor validates all navigation via guards before URL changes

The class is concrete — it can be instantiated directly. The framework packages re-export or subclass it purely to bind the public adapter name (and, for Solid, to add the dispose() alias).

Example

const bridge = new TanStackRouterBridgeBase(router, actor, routeMap);
bridge.connect();
return () => bridge.disconnect();

Extends

Constructors

Constructor

new TanStackReactRouterBridge(
router,
actor,
routeMap): TanStackRouterBridgeBase;

Defined in: play-tanstack-router/src/tanstack-router-bridge-base.ts:112

Create a TanStack Router bridge

Parameters

ParameterTypeDescription
routerTanStackRouterLikeTanStack Router instance (from createRouter)
actorRoutableActorXMachines actor instance
routeMapTanStackRouteMapLikeBidirectional mapping between state IDs and paths

Returns

TanStackRouterBridgeBase

Overrides

RouterBridgeBase.constructor

Methods

connect()

connect(): void;

Defined in: play-router/src/router-bridge-base.ts:151

Connect the router bridge to the Actor.

Sets up the TC39 Signal watcher for actor → router direction and starts watching router changes (framework-specific).

Ordering here is part of the bridge contract:

  • lastSyncedPath is seeded in the constructor from actor.currentRoute
  • the actor watcher is installed before adapter router subscriptions
  • initial sync then resolves deep-link vs restore using actor.initialRoute

Adapters that need custom initial-sync behavior should override getInitialRouterPath() rather than reordering connect() steps.

Returns

void

Inherited from

RouterBridgeBase.connect


disconnect()

disconnect(): void;

Defined in: play-router/src/router-bridge-base.ts:256

Disconnect the router bridge from the Actor.

Stops signal watching and unregisters framework-specific router listener.

Returns

void

Inherited from

RouterBridgeBase.disconnect