-1

I want to add parameters to url without refreshing the page. I have used history.pushState and history.replaceState. I put a debugger on the function in javascript, when I debug history.pushState, it replaces the url, but then it changes again to the previous.

What I want to is, e.g. below is my url

.../?id=1

Now I will click on one of my filters and the url must be as follows

.../?id=1,2

Then I will click on Search button to apply filter. What should be the best practices?

DhavalR
  • 1,409
  • 3
  • 29
  • 57

3 Answers3

3

You can use the following code to add parameters without refresh:

window.history.replaceState(null, null, "?param1=value");
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
0

here is a good example to follow:

https://css-tricks.com/snippets/javascript/get-url-and-url-parts-in-javascript/

You can use in filters comands like: onchange, onclick etc. for instant modification of URL

Sergiu Costas
  • 530
  • 4
  • 8
  • 26
-2

Better don't change your URL before you apply your filter. Save your filter parameters in some object, and change URL after user clicks submit

Winni
  • 85
  • 1
  • 7