①、定义方法 gelDelURL
gelDelURL() {
return window.location.href
.substring(0,window.location.href.indexOf("?"));
},
gelDelURL是得到已经删除参数的方法
②、使用方法
window.history.replaceState(null, null, this.gelDelURL());
window.history.replaceState 是用来替换当前页面的url的操作
举个例子
在执行①之前URL路径为:https://baidu.com?id=123456
执行①之后得到 https://baidu.com
执行②之后URL路径变为https://baidu.com