Get URL changed by pushstate
When I change url by:
history.pushState(null, null, '#/' + $(this).attr('href').substring(1));
And when I want to change this pushstate with:
function updateUrl() {
history.pushState(null, null, `${location.href}/?page=` + this.page);
}
And when I click to pagination buttons. I get link like this: http://example.com/foo/bar/#revs/?page=1/?page=2/?page3
<button onclick="updateUrl(1)">1</button>
<button onclick="updateUrl(2)">2</button>
But I need change only param page.
The reason your seeing the repeating ?page is because your getting the HREF which is getting the protocol, domain and any params.
Instead try something like this (with window.location.origin)..
function updateUrl() {
history.pushState(null, null, `$(location.origin)/?page=` + this.page);
}
Please or to participate in this conversation.