我有一个问题,我有一个pushState的标签:
history.pushState(null, null, '#/' + $(this).attr('href').substring(1));
而当我想改变这种pushState的有:
function updateUrl() {
history.pushState(null, null, `${location.href}/?page=` + this.page);
}
当我点击分页按钮。我得到的链接是这样的:http://example.com/foo/bar/#revs/?page=1/?page=2/?page3
<button onclick="updateUrl(1)">1</button>
<button onclick="updateUrl(2)">2</button>
但我需要改变只PARAM page
。我怎样才能解决这个问题?
使用location.href
只是增加了目前链接。建立基于链接:
location.origin + location.pathname + location.hash.split('/')[0] + '/?page=' + this.page
了解更多关于location对象。
您可以随时在浏览器的控制台,以了解它的结构访问location
对象。