0

I want to change my url on click without refreshing page. For example my URL is http://test.com?search=test

When I click any filter value on the search page like "category" then my URL should be:

http://test.com?search=test$category=cat1

When I click on another category it should be:

http://test.com?search=test&category=cat1,cat2

When I click a brand then the URL should be:

http://test.com?search=test$category=cat1,cat2&brand=br1

When I deselect a category then the URL should be:

http://test.com?search=test$category=cat2&brand=br1

Please help me.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Ravi Kant
  • 289
  • 4
  • 10

1 Answers1

1

You can change it via the history api

window.history.pushState("object or string", "Title", "/new-url");

In this case the relative /new-url will be set with the new title. You can experiment with it in the console. If you input this on stackoverflow.com the url will magically change to https://stackoverflow.com/new-url

Community
  • 1
  • 1
Kordi
  • 2,405
  • 1
  • 14
  • 13