Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replaceState with empty string: Javascript

I've got this url:

website.com/con?blog=true

What I do in javascript is:

if (getURLparams(blog)) {
   RandomFunction();
   // change the url
   window.history.replaceState({}, '?blog=true', "blog=false");
}

However, I do not want to use blog=false, in fact I want empty string there. I tried ""/'' but they didn't work. Any idea or alternative? Thanks

like image 347
popeye Avatar asked Oct 18 '17 08:10

popeye


1 Answers

You can set it to location.pathname:

window.history.replaceState({}, '', location.pathname);

This will remove the URL params.

like image 150
Kaiido Avatar answered Oct 19 '22 22:10

Kaiido