Skip to content

Class: SvelteSpaRouterBridge

API / @xmachines/play-svelte-spa-router / SvelteSpaRouterBridge

Defined in: play-svelte-spa-router/src/svelte-spa-router-bridge.ts:29

The Svelte SPA router bridge — it connects svelte-spa-router to RouterBridgeBase.

It implements the three abstract methods:

  • navigateRouterpush(path) from svelte-spa-router
  • watchRouterChangeswin.addEventListener("hashchange", ...)
  • unwatchRouterChangeswin.removeEventListener("hashchange", ...)

It overrides two optional hooks:

  • getInitialRouterPathrouter.loc.location
  • getInitialRouterSearch → the querystring of router.loc

The bridge inherits the restore-or-deeplink detection, isProcessingNavigation, and lastSyncedPath from RouterBridgeBase.

Param

actor

A Routable actor.

Param

routeMap

The bidirectional route map.

Param

win

The window-like object for the hashchange subscription. The default is the global window, when one exists. In an environment without a window, such as SSR or Node, the bridge skips the hashchange subscription. The constructor and connect() are then safe, as the documented behavior “it does nothing in an SSR environment” says. Give a mock in a test.

Extends

Constructors

Constructor

new SvelteSpaRouterBridge(
actor,
routeMap,
win?): SvelteSpaRouterBridge;

Defined in: play-svelte-spa-router/src/svelte-spa-router-bridge.ts:32

Parameters

ParameterType
actorRoutableActor
routeMapRouteMap
winWindowLike | undefined

Returns

SvelteSpaRouterBridge

Overrides

RouterBridgeBase.constructor

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 lastSyncedPath from actor.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

RouterBridgeBase.connect


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

Inherited from

RouterBridgeBase.disconnect