Remove parameter from query string without rebooting

Is it possible to remove a parameter from the query string using js, I tried below, unfortunately, this works in the browser console, not in the JS file.

var clean_uri = location.protocol + "//" + location.host+location.pathname; window.history.replaceState({}, document.title, clean_uri); 

what would be the best way to do this.

+5
source share
1 answer

The reason this will only work in the browser is because the window.history API is only available in your browser. I'm not quite sure what you mean by "from file". But, as one commenter noted, the problem is where it runs. If, for example, you are doing this in a Node environment and not in a browser, there is no window.history api. Node does not even have a window object.

Since you added the AngularJs flag, it is possible that routing within the application listens for URL changes and will act on them. Angular may have its own way of allowing you to change the url, but I'm not knowledgeable enough to help with this.

+1
source

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


All Articles