editLink |
---|
API Documentation / RouterHistory
Interface implemented by History implementations that can be passed to the router as Router.history
• Readonly
base: string
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
• Readonly
location: string
Current History location
• Readonly
state: HistoryState
Current History state
▸ createHref(location
): string
Generates the corresponding href to be used in an anchor tag.
Name | Type | Description |
---|---|---|
location |
string |
history location that should create an href |
string
▸ destroy(): void
Clears any event listener attached by the history implementation.
void
▸ go(delta
, triggerListeners?
): void
Traverses history in a given direction.
Name | Type | Description |
---|---|---|
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 |
void
Example
myHistory.go(-1) // equivalent to window.history.back()
myHistory.go(1) // equivalent to window.history.forward()
▸ listen(callback
): () => void
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
Name | Type | Description |
---|---|---|
callback |
NavigationCallback |
listener to attach |
fn
a callback to remove the listener
▸ (): void
void
▸ push(to
, data?
): void
Navigates to a location. In the case of an HTML5 History implementation,
this will call history.pushState
to effectively change the URL.
Name | Type | Description |
---|---|---|
to |
string |
location to push |
data? |
HistoryState |
optional HistoryState to be associated with the navigation entry |
void
▸ replace(to
, data?
): void
Same as RouterHistory.push but performs a history.replaceState
instead of history.pushState
Name | Type | Description |
---|---|---|
to |
string |
location to set |
data? |
HistoryState |
optional HistoryState to be associated with the navigation entry |
void