You do not need to grab the injector and $ state.go, not at all. The argument to the otherwise method may be a URL that may contain parameters in it .
So, in your particular case, the following code can lead you to base_url / search? query = x
$urlRouterProvider.otherwise("/search?query=x");
Alternatively, the argument may be a function that returns a URL. If you donโt know what URL parameters you might have, you just need to get the parameters from $location and then format them in a string similar to the URL and return it.
$urlRouterProvider.otherwise(function($injector, $location) { var params = $location.search() // format params to 'p1=v1&p2=v2' style var formatted = Object.keys(params).map(function(key) { return key + '=' + params[key] }).join('&') return '/search?' + formatted });
source share