在 AngularJS 路由文件中,有一个 otherwise
路由选项,可以替换 404 错误页面:
$routeProvider
.when(...)
.otherwise({
redirectTo: 'my/path'
});
有没有办法这样做,使得otherwise重定向到不在应用程序中的页面?我尝试了。$routeProvider
.when(...)
.otherwise({
redirectTo: 'http://example.com'
});
但是这只是试图重定向到我的应用程序中不存在的路径。我知道的解决方案是在顶层控制器的$scope.$on('$routeChangeStart')
中进行手动重定向,但这会导致大量代码重复(而且很丑陋)。是否有更好的方法?