Search code examples
angularjsangularjs-routing

how to redirect $routeProvider.otherwise() keeping the given query parameters


Let say I go to /unknown-route?a=hello&b=world and $routeProvider doesnt recognize it and redirect to the otherwise route:

otherwise({
  redirectTo: '/default-route'
});

Is it possible to pass the given parameters to the redirected route.

Here it would be /default-route?a=hello&b=world


Solution

  • I found a working solution:

    otherwise({
      redirectTo: function() {
        return '/default-route' + location.search;
      }
    })