history-state
v2.0.0
Published
Allows you to monitor and make changes to a page’s history state.
Downloads
27
Maintainers
Readme
history-state
history-state allows you to monitor and make changes to a page’s history state.
Install
$ npm install history-state
API
By default, the mechanisms used are history.pushState
and window.onpopstate
, with older browsers falling back to location.hash
and window.onhashchange
. This behaviour can be overridden by passing the constructor an options object, detailed below.
var state = require('history-state')({
// Use only location.hash/onhashchange…
hash: true,
// …or use only history.pushState/onpopstate.
pushState: true
})
state.change('/some-path')
state.on('change', function() {
console.log(location.pathname)
> '/some-path'
})
// Toggle the window listeners.
state.stop()
state.start()