How can I remove the query string from the url after the page loads?

前端 未结 10 1132
栀梦
栀梦 2020-12-16 10:03

I have a URL with a long query string attached to it. After the page loads, I do not require the query string. So I want to remove the query string from the address bar with

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-16 10:43

    I use this code snippit in my personal projects where i need to remove URL params without re-loading:

    var newURL = location.href.split("?")[0];
    window.history.pushState('object', document.title, newURL);
    

提交回复
热议问题