Class: TanStackReactRouterBridge
API / @xmachines/play-tanstack-react-router / TanStackReactRouterBridge
Defined in: play-tanstack-router/src/tanstack-router-bridge-base.ts:107
The shared TanStack Router adapter. It implements the RouterBridge protocol through RouterBridgeBase
Remarks
The class extends RouterBridgeBase, and the base class does all the common lifecycle work and synchronization work. This class adds the TanStack navigation methods and subscription methods that the React adapter and the Solid adapter share.
The bridge subscribes to router.history, not to
router.subscribe(“onBeforeLoad”). Therefore it also receives a browser BACK or
FORWARD navigation, which is a popstate event. The
router.subscribe(“onBeforeLoad”) method works only when the Transitioner
component of TanStack is mounted, which means inside a complete
router.history.subscribe(router.load).
Architectural invariants:
- INV-02 (Passive Infrastructure): the router reflects the actor state. It never decides
- The actor checks every navigation with its guards before the URL changes
The class is concrete. You can create an instance of it directly. Each framework
package re-exports it, or makes a subclass of it, only to bind the public name of
the adapter. The Solid package also adds 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:117
Creates a TanStack Router bridge
Parameters
| Parameter | Type | Description |
|---|---|---|
router | TanStackRouterLike | The TanStack Router instance from createRouter |
actor | RoutableActor | The XMachines actor instance |
routeMap | TanStackRouteMapLike | The bidirectional map between the state IDs and the paths |
Returns
TanStackRouterBridgeBase
Overrides
Methods
connect()
connect(): void;Defined in: play-router/src/router-bridge-base.ts:158
Connects the router bridge to the Actor.
The method installs the TC39 Signal watcher of the direction from the actor to the router. It then starts the watch of the router changes, which each framework does in its own way.
The order of these steps is part of the contract of the bridge:
- The constructor seeds
lastSyncedPathfromactor.currentRoute - The method installs the actor watcher before the router subscriptions of the adapter
- The first synchronization then separates a deep link from a restore, with
actor.initialRoute
An adapter that needs a different behavior of the first synchronization overrides
getInitialRouterPath(). It does not change the order of the steps of
connect().
Returns
void
Inherited from
disconnect()
disconnect(): void;Defined in: play-router/src/router-bridge-base.ts:270
Disconnects the router bridge from the Actor.
The method stops the watch of the signal, and it removes the router listener of the framework.
Returns
void