How to Reload the Page Without the Query Parameters

How to reload a page without its parameters?

Use the location object

// similar behavior as an HTTP redirect
window.location.replace(location.protocol + '//' + location.host + location.pathname);

// similar behavior as clicking on a link
window.location.href = location.protocol + '//' + location.host + location.pathname;

angular how to refresh the page without losing the query string they pass to me

Instead of doing window.location.reload (which I'd argue is an anti-pattern to angular), you can do this within the router and preserve the query string with Navigation Extras

this.router.navigate(['/'], queryParamsHandling: "preserve"});

Can a plain HTML link (A) reload a page without query string values

I think I know a trick. When you use a <form> tag with empty action and no (or GET) method parameter it will use your url but will replace the GET parameters (query string) with the values in your form, so:

On page http://example.com/foo.html?query=string

<form action="">
<input type="submit" value="hello" />
</form>

If you click on the button you will get to:

  • http://example.com/foo.html (Firefox 8)
  • http://example.com/foo.html (Internet Explorer 9)
  • http://example.com/foo.html? (Chrome 15)
  • http://example.com/foo.html? (Safari 5)

Edit: the trailing question mark is likely a Webkit issue.

How to reload page without _layout query string parameter

You can use regular expression and remove all instance of _layout

  location.href=location.href.replace(/&?_layout=([^&]$|[^&]*)/i, "");


Related Topics



Leave a reply



Submit