I am debugging a large piece of javascript and am having trouble figuring out what is going on with the browser back button as it relates to pushState() and replaceState(). I have the following prototype method:
SolrUrl.prototype.storeQueryObject = function(data) {
var newUrl = window.location.protocol
+ "//"
+ window.location.host
+ window.location.pathname
+ "?"
+ $.param(data);
// window.history.pushState(newUrl);
window.history.pushState({
path: newUrl
}, "", newUrl);
};
I have a faceted search that allows me to do multi-level filtering. The above works as it allows me to filter different queries and use the back button to return to previous filters but I can not use the browser 'back' button once I get back to the intial state of the search. For example, if I go to google.com -> mysite.com -> and then filter my search to "components", I can use the back button to get back to the initial state of mysite.com, but cannot use it to return to google.com.
I can partially solve this problem by changing pushState to replaceState, but this does not allow me to use the back button to go back through filter states. For example, when using replaceState in the above function. If I go to google.com -> mysite.com -> filter "components" -> filter -> "component type" and hit the back button, it takes me back to mysite.com. What am I doing wrong? How can I make the browser's back button to go back through filter states as well as previous urls?