Js sets default url after using history.pushstate

I have a problem. How can I remove from url content added by history.pushState? For example, I have this url:

site.com 

Ok, now I am updating this url:

 site.com/site/subsite 

How can I restore the default URL (site.com).

I try history.pushState("",document.title,document.location.pathname) , but

document.location.pathname - "site.com/site/subsite"

and I will return to the starting point: (

+4
source share
1 answer
 history.pushState("", document.title, "/"); 

It will completely remove the state from the domain URL.

+4
source

Source: https://habr.com/ru/post/1393541/


All Articles