0

I would like to change address url without navigation. I do it like

    var url = window.location.href;
     url = url.split('#');
     var url_ = url[0] + '?task=product&url=' + selectedUrl;
  history.pushState(null, null, url_);

After then I enter on url in address bar and navigated to this url url[0] + '?task=product&url=' + selectedUrl. But the problem comes when I navigate back, the address was changed but not page(the page is not load for changed url).

Now, How can I navigate back and page load by this url?

Vahe Akhsakhalyan
  • 2,140
  • 3
  • 24
  • 38
  • Possible duplicate of [Back button / backspace does not work with window.history.pushState](https://stackoverflow.com/questions/19335372/back-button-backspace-does-not-work-with-window-history-pushstate) – t.niese Sep 21 '17 at 13:03
  • `pustState` only changes the url and stores some meta information but not the content of the page. You need to listen to the [popstate](https://developer.mozilla.org/en-US/docs/Web/Events/popstate) event and update the content of your page accordingly. – t.niese Sep 21 '17 at 13:05

1 Answers1

1

history.pushState only manipulates the browser history. I'm a bit confused by you're wording but you can always just

window.location = url;

To redirect to where you want to go

Robbie Milejczak
  • 5,664
  • 3
  • 32
  • 65
  • yeah, but when I click in browser Back button, it not load the page, only change the url – Vahe Akhsakhalyan Sep 21 '17 at 13:02
  • I'm still not sure what you're trying to do. I don't think it works like you think it does, I would give this a read https://developer.mozilla.org/en-US/docs/Web/API/History_API This may help as well https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate – Robbie Milejczak Sep 21 '17 at 13:06