Skip to content

Interface: DisposableBrowserHistory

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

Defined in: play-dom-router/src/create-browser-history.ts:87

The history that createBrowserHistory builds.

It IS a BrowserHistory, and it says one thing more: subscribe hands back a Cleanup, so a caller may release it with using and write no teardown.

const history = createBrowserHistory({ window });
{
using stop = history.subscribe((location) => render(location));
// stop() runs at the end of the scope, and after an exception too
}

The history itself is a Disposable too, and BrowserHistory.destroy is what it releases. destroy() unpatches history.pushState and history.replaceState of the window, so a scope that drops the history without it leaves the global patched:

{
using history = createBrowserHistory({ window });
history.push("/first");
// destroy() runs at the end of the scope, and after an exception too
}

A narrowed return and not a narrowed interface: the return type of a method may narrow in an extension, so this costs an implementer of BrowserHistory nothing. The dispose key is added here, and not on BrowserHistory, for the same reason.

Extends

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
locationreadonlyobjectReturns the state of the current locationBrowserHistory.locationplay-dom-router/src/create-browser-history.ts:7
location.hashpublicstring--play-dom-router/src/create-browser-history.ts:10
location.pathnamepublicstring--play-dom-router/src/create-browser-history.ts:8
location.searchpublicstring--play-dom-router/src/create-browser-history.ts:9
location.statepublicunknown--play-dom-router/src/create-browser-history.ts:11

Methods

[dispose]()

dispose: void;

Defined in: play-dom-router/src/create-browser-history.ts:91

Releases the history with BrowserHistory.destroy. It is idempotent.

Returns

void


back()

back(): void;

Defined in: play-dom-router/src/create-browser-history.ts:28

Returns

void

Inherited from

BrowserHistory.back


createHref()

createHref(path): string;

Defined in: play-dom-router/src/create-browser-history.ts:46

Creates an href from a path

Parameters

ParameterType
pathstring

Returns

string

Inherited from

BrowserHistory.createHref


destroy()

destroy(): void;

Defined in: play-dom-router/src/create-browser-history.ts:54

Cleans up.

A second call is safe. When more than one wrapper shares the same window.history, the last wrapper restores the original methods.

Returns

void

Inherited from

BrowserHistory.destroy


forward()

forward(): void;

Defined in: play-dom-router/src/create-browser-history.ts:29

Returns

void

Inherited from

BrowserHistory.forward


go()

go(delta): void;

Defined in: play-dom-router/src/create-browser-history.ts:27

Moves back or forward in the history

Parameters

ParameterType
deltanumber

Returns

void

Inherited from

BrowserHistory.go


push()

push(path, state?): void;

Defined in: play-dom-router/src/create-browser-history.ts:17

Pushes a new URL to the history

Parameters

ParameterType
pathstring
state?unknown

Returns

void

Inherited from

BrowserHistory.push


replace()

replace(path, state?): void;

Defined in: play-dom-router/src/create-browser-history.ts:22

Replaces the current URL in the history

Parameters

ParameterType
pathstring
state?unknown

Returns

void

Inherited from

BrowserHistory.replace


subscribe()

subscribe(...args): Cleanup;

Defined in: play-dom-router/src/create-browser-history.ts:88

Subscribes to the history changes. It returns a function that cancels the subscription.

The return is a plain function here, because a consumer IMPLEMENTS this interface to inject its own history for a test or for SSR. A Cleanup return would refuse every implementation that hands a plain function back. DisposableBrowserHistory narrows it for the value that createBrowserHistory builds, which nothing implements.

Parameters

ParameterType
…args[(location) => void]

Returns

Cleanup

Overrides

BrowserHistory.subscribe