query-state is a cheeky module that uses history API and encodeURIComponent magic to maintain the application state in the query string.
Get it:npm install query-state
Sample usage:
12345678910111213141516171819202122232425262728
constqueryState=require('query-state');// create a new query state instanceconstqs=queryState();// get current application state from the hash string:constappState=qs.get();// you can also monitor for changes in the query string:qs.onChange(function(appState){// prints new application state on each hash updateconsole.log('app state changed!',appState);});// If you want to set a new value in the app state:qs.set('answer',42);// Now the query string will have `answer=42` part in it.console.log(window.location.hash.indexOf('answer=42'))// prints value > 0.// You can also set multiple values at once:qs.set({name:'Haddaway',song:'What is love?'});// NOTE: The call above merges new properties. It appends two new properties to // the current query string