Skip to content

vue-router / RouterHistory

RouterHistory ​

Alpha

Interface implemented by History implementations that can be passed to the router as Router.history

Properties ​

base ​

ts
readonly base: string;

Alpha

Base path that is prepended to every url. This allows hosting an SPA at a sub-folder of a domain like example.com/sub-folder by having a base of /sub-folder


location ​

ts
readonly location: string;

Alpha

Current History location


state ​

ts
readonly state: HistoryState;

Alpha

Current History state

Methods ​

createHref() ​

ts
createHref(location): string;

Alpha

Generates the corresponding href to be used in an anchor tag.

Parameters ​

location ​

string

history location that should create an href

Returns ​

string


destroy() ​

ts
destroy(): void;

Alpha

Clears any event listener attached by the history implementation.

Returns ​

void


go() ​

ts
go(delta, triggerListeners?): void;

Alpha

Traverses history in a given direction.

Parameters ​

delta ​

number

distance to travel. If delta is < 0, it will go back, if it's > 0, it will go forward by that amount of entries.

triggerListeners? ​

boolean

whether this should trigger listeners attached to the history

Returns ​

void

Example ​

js
myHistory.go(-1) // equivalent to window.history.back()
myHistory.go(1) // equivalent to window.history.forward()

listen() ​

ts
listen(callback): () => void;

Alpha

Attach a listener to the History implementation that is triggered when the navigation is triggered from outside (like the Browser back and forward buttons) or when passing true to RouterHistory.back and RouterHistory.forward

Parameters ​

callback ​

NavigationCallback

listener to attach

Returns ​

a callback to remove the listener

() => void


push() ​

ts
push(to, data?): void;

Alpha

Navigates to a location. In the case of an HTML5 History implementation, this will call history.pushState to effectively change the URL.

Parameters ​

to ​

string

location to push

data? ​

HistoryState

optional HistoryState to be associated with the navigation entry

Returns ​

void


replace() ​

ts
replace(to, data?): void;

Alpha

Same as RouterHistory.push but performs a history.replaceState instead of history.pushState

Parameters ​

to ​

string

location to set

data? ​

HistoryState

optional HistoryState to be associated with the navigation entry

Returns ​

void

Released under the MIT License.