0

I have been trying to change a parameter of my URL without reloading the site, however, I am not 100% sure what's wrong with my code. What happens in the URL is removing all the parameters and replacing it for a simple string. i.e http://localhost:50754/Signup555

And I want to change from http://localhost:50754/Signup?A=1&B=2&C=3 to http://localhost:50754/Signup?A=1&B=2&C=6

  function changeQueryString(searchString, documentTitle) {
        documentTitle = typeof documentTitle !== 'Pid' ? documentTitle : document.title;
        var urlSplit = (window.location.href).split("?");
        var obj = {
            Title: documentTitle,
            Url: urlSplit[0] + searchString
        };
        history.pushState(obj, obj.Title, obj.Url);
    }

<a onclick="changeQueryString('555', 'Pid')"> change it</a>

Thanks in advance.

2 Answers2

0

You can use a "router" library. Navigo is a decent example.

dzimney
  • 565
  • 1
  • 5
  • 15
0

Your function should be:

  function changeQueryString(searchString, documentTitle) {
     window.history.replaceState(null, null, window.location.pathname+"?A="+searchString[0]+"&B="+searchString[1]+"&C="+searchString[2]);
    }

<a onclick="changeQueryString('555', 'Pid')"> change it</a>
Batsheva Hansav
  • 316
  • 2
  • 11