0

I am creating the search page for an e-commerce website, where we can search by different facets which creates dynamic URL and I am refreshing views only without refreshing page. Now if user press back and forth button of the browser, I want to reload views only with relevant data without reloading the page. I am using below code to capture back and forth button event But its reloading page automatically.

Is there any way to prevent this page refresh?

window.onpopstate = function (event) {
    console.log("pop!");
    window.getProducts();
    window.getArticles();
    event.preventDefault();
    event.stopImmediatePropagation();
};
Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Prasad
  • 1
  • 2
  • which UI framework are you using? – Sumesh TG Jul 13 '18 at 07:11
  • 1
    Possible duplicate of [Is it possible to e.preventDefault in window.onPopState?](https://stackoverflow.com/questions/32432296/is-it-possible-to-e-preventdefault-in-window-onpopstate) – sjahan Jul 13 '18 at 07:15

1 Answers1

0

You can use h5 history to change url, like this

window.history.pushState('', '','about');

and add popstate listener to window.