防止将history.replaceState附加到wordpress中的网址

问题描述

我正在使用window.history.replaceState动态更改URL,而无需在我的WordPress网站中重新加载页面。一切正常。但是,它是追加到url而不是更改url。

例如:

https://example.com/category/post-title-slug

它应该像这样改变 https://example.com/category/post-title-slug-2

但是,它正在像这样改变 https://example.com/category/post-title-slug/https://example.com/category/post-title-slug-2

我的脚本

var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + page_url;
window.history.replaceState({ path: newurl },'',newurl);

我尝试了所有可能的方法来修复它。但是什么都行不通。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)