Skip to content

Instantly share code, notes, and snippets.

Created October 24, 2021 18:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Querystate w/ history
import querystate from 'querystate'
import nanobus from 'nanobus'
const state = querystate()
const bus = nanobus()
// emit state on history change
var pushState = history.pushState
var popState = history.popState
history.pushState = function(s) {
bus.emit('history', state)
return pushState.apply(history, arguments)
window.onpopstate = function (s) {
const urlParams = new URLSearchParams(
urlParams.forEach((value, key) => {
state.queryState[key] = value
bus.emit('history', state)
export { state as default, state, bus }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment