I have this line of code here:
if(window.location.search == "?mytoken=abc") {
          window.history.replaceState(null, '', window.location.pathname);
}
What this code does is check if the query parameter mytoken exists and if it does, replace the current page without the query parameter and this works perfectly.
But I did notice I did have 2 history items in my browser history, one with the query parameter and the other without the query parameter. I am looking for away to remove the item with the query parameter from the browser history. Is this possible?
I found this code in my project, if it helps:
history.listen((newLocation, action) => {
      if (action === "PUSH") {
        if (
          newLocation.pathname !== this.currentPathname ||
          newLocation.search !== this.currentSearch
        ) {
          // Save new location
          this.currentPathname = newLocation.pathname;
          this.currentSearch = newLocation.search;
          // Clone location object and push it to history
          history.push({
            pathname: newLocation.pathname,
            search: newLocation.search,
          });
        }
      } else {
        // Send user back if they try to navigate back
        history.go(1);
      }
    });
This is called every time a new page comes up.
 
     
     
     
    