如何重定向$ routeProvider.otherwise()保持给定的查询参数

Jor*_*ane 9 angularjs angularjs-routing

假设我去了/unknown-route?a=hello&b=world并且$routeProvider不认识它并重定向到其他路线:

otherwise({
  redirectTo: '/default-route'
});
Run Code Online (Sandbox Code Playgroud)

是否可以将给定参数传递给重定向路由.

这将是 /default-route?a=hello&b=world

Jor*_*ane 12

我找到了一个有效的解决方

otherwise({
  redirectTo: function() {
    return '/default-route' + location.search;
  }
})
Run Code Online (Sandbox Code Playgroud)