I do it like this:
step 1 - save the starting URL of the page (which has not changed yet)
var savedPageStateURL = window.location.pathname;
2 - ( , )
window.history.replaceState( {}, null , url );
3 -
if( 'pushState' in window.history && window.history.state )
window.history.replaceState( {}, null , savedPageStateURL );