How to remove GET parameters using AngularJS?

#/order/123?status=success 

shows the route '/order/:id' and occupies OrderCtrl .

As soon as we gain access to $routeParams.query , we want to clear the URL to #/order/123 . How can this be achieved?

+8
angularjs get url-routing
source share
2 answers

Using the $location service, you can remove the search parameter by setting it to zero:

 $location.search( 'status', null ); 

But you should notice that by default this will reload the current route. If you do not want to reload the current route, you can disable it in the route definition:

 $routeProvider.when( '/order/:id', { // yada yada... reloadOnSearch: false }); 

But $routeUpdate still works and can respond to.

+17
source share

A more efficient way to remove all search options is likely to be

 $location.search({}); 
+12
source share

All Articles