When working with AngularJS routes, there is the option to use an otherwise
route as a replacement for a 404 error:
$routeProvider
.when(...)
.otherwise({
redirectTo: 'my/path'
});
Is it possible to configure the otherwise route to redirect to a page that is outside of the application? I attempted to accomplish this by using:
$routeProvider
.when(...)
.otherwise({
redirectTo: 'http://example.com'
});
However, this simply tried to redirect to that path within my app, which does not exist. The workaround that I am aware of involves manually handling redirection in a $scope.$on('$routeChangeStart')
event listener in a top-level controller, but this approach results in code duplication and is considered unsightly. Is there a more efficient solution available?