replaceState用空字符串:Javascript

我有这个url:

website.com/con?blog=true 

我在javascript中做的是:

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

但是,我不想使用blog=false ,实际上我想要空字符串。 我试过"" / ''但他们没有用。 任何想法或替代? 谢谢

您可以将其设置为location.pathname

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

这将删除URL参数。

你可以尝试..清空函数replaceState的最后一个参数。 像这样。

 window.history.replaceState({}, '?blog=true', ""); 

要么

 window.history.replaceState({}, '?blog=true');