2

Our single page application uses a custom router. We replace invalid urls with valid ones using history.replaceState(...) .

The urls look like ...

http://domain.com/#view=employee/details&param1=1&param2=2

When it is time to replace an invalid url, we call

history.replaceState(null, null, "#view=employee/details&param1=11&param2=22");

But the above code keeps adding to the browser history. What am I doing wrong?

DarkAjax
  • 15,175
  • 11
  • 52
  • 65
  • take a look on [this](http://stackoverflow.com/questions/136458/change-the-url-in-the-browser-without-loading-the-new-page-using-javascript) – Sergey Boiko Jul 28 '14 at 19:04

1 Answers1

0

replaceState adds the entry to the browser history if it does not already exist. If it already exists it will "REPLACE" it, basically it will take the older entry and replace it with one using the current timestamp.

If your goal is to have no entries added to the browser history, that is not possible using JavaScript.

If your problem is that those entries in the browser history load pages that generate a 404 error, you have to monitor popState and show the appropriate page, otherwise you are creating fake URLs.

Tiramisu
  • 434
  • 3
  • 9