-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,361
  • 2
  • 25
  • 53

3 Answers3

1

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

window.history.replaceState(null, null, "?param1=value");
סטנלי גרונן
  • 2,740
  • 21
  • 43
  • 62
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
  • 480
  • 4
  • 7
  • 24
-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
  • 75
  • 6