After reading and processing a query-string value from the URL, for example
http://myurl.com/#/?foo=baa
I can change the URL to
http://myurl.com/#/?foo=
by using
$location.search('myQueryStringParameter', '');
How do I get rid of the query-string altogether (without explicit redirects or server side action and so on) so that only
http://myurl.com/#/
remains in the browser? It should be fairly simple, but I can't find any reference.
You were close, you needed to set null
$location.search('myQueryStringParameter', null);
From ng.$location documentation
If search is a string, then paramValue will override only a single search parameter. If paramValue is an array, it will set the parameter as a comma-separated value. If paramValue is null, the parameter will be deleted.
Try this:
$location.url($location.path())
See documentation for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With