history
Wrappers around the History API for pushing and replacing entries,
navigating back/forward, and listening for popstate.
Import: @rtorcato/browser-common/history
๐ MDN: History API ยท ๐ caniuse: history
Exampleโ
import { pushState, onPopState, goBack } from '@rtorcato/browser-common/history'
pushState('/page/2', { page: 2 })
const off = onPopState((event) => {
console.log('navigated to', event.state)
})
goBack()
off()
Exportsโ
pushState(url, state?, title?)โ pushes a new history entryreplaceState(url, state?, title?)โ replaces the current history entrygoBack()โ navigates back one entrygoForward()โ navigates forward one entrygo(delta)โ navigates to a relative position in the history stackonPopState(callback)โ listens forpopstate; returns an unsubscribe function
See the API reference for full signatures.