Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reload the page without the query parameters?

People also ask

How do I refresh the current page?

You can use the location. reload() JavaScript method to reload the current URL. This method functions similarly to the browser's Refresh button. The reload() method is the main method responsible for page reloading.

How to redirect page in JavaScript without refresh?

history. pushState({page: "another"}, "another page", "example. html"); This will change the URL, but not reload the page.

What is URLSearchParams?

The URLSearchParams interface defines utility methods to work with the query string of a URL.


window.location = window.location.href.split("?")[0];

There are a few ways to go about it:

window.location = window.location.href.split("?")[0];

Or, alternatively:

window.location = window.location.pathname;

This is the best and easiest way,

// similar to HTTP redirect
window.location.replace(location.pathname);

I typically try to avoid making unnecessary function calls whenever I can, especially when the information I need is already provided to me by the DOM. That said, here is probably objectively the best solution:

window.location = window.location.pathname + window.location.hash;

As pointed out in a comment by user qbert65536, there are many popular modern frameworks that use the hash to denote views and paths, which is why using window.location.pathname alone is not enough.


Try this Javascript:

location = location.pathname;