Skip to content

Interface: MountableRouterBridge

API / @xmachines/play-router / MountableRouterBridge

Defined in: play-router/src/types.ts:416

A RouterBridge whose machine is mounted at a URL prefix that can MOVE while the bridge stays connected.

Every bridge on RouterBridgeBase satisfies this interface. The interface exists so that a provider component moves a live bridge instead of a teardown of it: a host route that renders again with a new prefix keeps the actor, the route map, and its LRU cache.

The mount that moves says WHERE an actor lives, and never WHICH actor lives there. An actor never changes identity, so a new identity is a new actor, and a new actor takes a new bridge.

Example

// The host moved this actor to another place in its URL space. `machineId` names
// WHICH document the actor runs, and it does not change: a new identity is a new
// actor, and therefore a new bridge, because one actor takes one bridge.
bridge.setBasePath("/:region/:machineId/play", { region: "us", machineId });

Extends

Properties

PropertyModifierTypeDescriptionDefined in
basePathreadonlystringThe resolved URL prefix of the mount, or "" when the machine owns the complete router.play-router/src/types.ts:418
basePathParamsreadonlyReadonly<Record<string, string>>The resolved values of the :param segments of the mount, or {} for a prefix without a param. These params belong to the HOST, so they travel in NO play.route event — the machine is authoritative over its own params. This accessor is therefore the one way a host reads them back, and it cannot go stale: setBasePath() can move the mount while the machine stays on the same route, and no event goes out.play-router/src/types.ts:428

Methods

connect()

connect(): void | Promise<void>;

Defined in: play-router/src/types.ts:376

Connects the router bridge to the Actor

The infrastructure calls it when it must start the observation of the Actor signals, and when it must bring its own state, for example the browser URL, in line with the Actor state.

Returns

void | Promise<void>

The promise that resolves after the connection, or void for a synchronous connection

Example

const bridge: RouterBridge = createBridge(actor, router);
await bridge.connect();
// The bridge observes the actor.currentRoute signal now

Inherited from

RouterBridge.connect


disconnect()

disconnect(): void | Promise<void>;

Defined in: play-router/src/types.ts:392

Disconnects the router bridge from the Actor

The infrastructure calls it when it must stop the observation and free its resources, for example a signal watcher and an event listener.

Returns

void | Promise<void>

The promise that resolves after the disconnection, or void for a synchronous disconnection

Example

await bridge.disconnect();
// The bridge stopped its observation, and it freed its resources

Inherited from

RouterBridge.disconnect


setBasePath()

setBasePath(basePath?, basePathParams?): void;

Defined in: play-router/src/types.ts:436

Moves the machine to a different mount point.

The call runs the same first-synchronization decision as connect() against the new prefix, and it reconciles nothing when the prefix resolves to the current one. An absent basePath removes the prefix.

Parameters

ParameterType
basePath?string
basePathParams?Record<string, string | number>

Returns

void