@rtorcato/browser-common / history
history
Functions
pushState()
pushState(
url,state?,title?):void
Defined in: history/index.ts:12
Pushes a new entry onto the browser's history stack.
Parameters
url
string
The URL to push.
state?
unknown = {}
Optional state object.
title?
string = ''
Optional title (not widely used).
Returns
void
Example
import { pushState } from '@rtorcato/browser-common/history'
pushState('/page/2', { page: 2 })
replaceState()
replaceState(
url,state?,title?):void
Defined in: history/index.ts:29
Replaces the current entry on the browser's history stack.
Parameters
url
string
The URL to replace with.
state?
unknown = {}
Optional state object.
title?
string = ''
Optional title (not widely used).
Returns
void
Example
import { replaceState } from '@rtorcato/browser-common/history'
replaceState('/login', { from: '/dashboard' })
goBack()
goBack():
void
Defined in: history/index.ts:43
Navigates back in the browser's history.
Returns
void
Example
import { goBack } from '@rtorcato/browser-common/history'
goBack()
goForward()
goForward():
void
Defined in: history/index.ts:57
Navigates forward in the browser's history.
Returns
void
Example
import { goForward } from '@rtorcato/browser-common/history'
goForward()
go()
go(
delta):void
Defined in: history/index.ts:72
Navigates to a specific point in the browser's history.
Parameters
delta
number
The position in the history stack (e.g., -1 for back, 1 for forward).
Returns
void
Example
import { go } from '@rtorcato/browser-common/history'
go(-2)
onPopState()
onPopState(
callback): () =>void
Defined in: history/index.ts:89
Adds a listener for popstate events (when the active history entry changes).
Parameters
callback
(event) => void
The callback to run on popstate.
Returns
A function to remove the event listener.
() => void
Example
import { onPopState } from '@rtorcato/browser-common/history'
const off = onPopState((e) => console.log(e.state))
off()