Skip to main content

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 entry
  • replaceState(url, state?, title?) โ€” replaces the current history entry
  • goBack() โ€” navigates back one entry
  • goForward() โ€” navigates forward one entry
  • go(delta) โ€” navigates to a relative position in the history stack
  • onPopState(callback) โ€” listens for popstate; returns an unsubscribe function

See the API reference for full signatures.