Interface: BrowserHistory
API / @xmachines/play-dom-router / BrowserHistory
Defined in: play-dom-router/src/create-browser-history.ts:3
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
location | readonly | object | Returns the state of the current location | play-dom-router/src/create-browser-history.ts:7 |
location.hash | public | string | - | play-dom-router/src/create-browser-history.ts:10 |
location.pathname | public | string | - | play-dom-router/src/create-browser-history.ts:8 |
location.search | public | string | - | play-dom-router/src/create-browser-history.ts:9 |
location.state | public | unknown | - | 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.
destroy() unpatches history.pushState and history.replaceState of the window,
so a scope that drops the history without it leaves the global patched. The key lets
a scope do that work:
{ using history = createBrowserHistory({ window }); history.push("/first"); // destroy() runs at the end of the scope, and after an exception too}An implementation writes it as one line beside destroy, and the two therefore
release the same work:
destroy() { ... },[DISPOSE]() { this.destroy(); },Returns
void
back()
back(): void;Defined in: play-dom-router/src/create-browser-history.ts:28
Returns
void
createHref()
createHref(path): string;Defined in: play-dom-router/src/create-browser-history.ts:58
Creates an href from a path
Parameters
| Parameter | Type |
|---|---|
path | string |
Returns
string
destroy()
destroy(): void;Defined in: play-dom-router/src/create-browser-history.ts:66
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
forward()
forward(): void;Defined in: play-dom-router/src/create-browser-history.ts:29
Returns
void
go()
go(delta): void;Defined in: play-dom-router/src/create-browser-history.ts:27
Moves back or forward in the history
Parameters
| Parameter | Type |
|---|---|
delta | number |
Returns
void
push()
push(path, state?): void;Defined in: play-dom-router/src/create-browser-history.ts:17
Pushes a new URL to the history
Parameters
| Parameter | Type |
|---|---|
path | string |
state? | unknown |
Returns
void
replace()
replace(path, state?): void;Defined in: play-dom-router/src/create-browser-history.ts:22
Replaces the current URL in the history
Parameters
| Parameter | Type |
|---|---|
path | string |
state? | unknown |
Returns
void
subscribe()
subscribe(listener): Cleanup;Defined in: play-dom-router/src/create-browser-history.ts:53
Subscribes to the history changes. It returns the release of the subscription.
A caller runs the release, or a scope releases it:
using stop = history.subscribe((location) => render(location));// stop() runs at the end of the scope, and after an exception tooA Cleanup IS a () => void, so a caller that runs it keeps that code. An
implementation of this interface builds one with asCleanup of @xmachines/play,
which this package re-exports:
subscribe(listener) { listeners.add(listener); return asCleanup(() => listeners.delete(listener));}Parameters
| Parameter | Type |
|---|---|
listener | (location) => void |