也许可以通过以下方式解决$routeProvider http://docs.angularjs.org/api/ng.%24routeProvider:
$routeProvider.when('/redirect/:redirectParams', {templateUrl: 'partials/homePartial', controller: redirectController});
$routeProvider.when('/home', {templateUrl: 'partials/homePartial', controller: homeController});
$routeProvider.when('/someRoute', {templateUrl: 'partials/somePartial', controller: someController});
$routeProvider.when('/error/', {templateUrl: 'partials/errorPartial', controller: errorController});
$routeProvider.when('/error/:errorMessage', {templateUrl: 'partials/errorPartial', controller: errorController});
$routeProvider.otherwise({redirectTo: '/error'})
只要让$routeProvider
当找不到路由时重定向到错误页面。
Edit:
我在上面的例子中添加了一个redirectController。该控制器将读取$routeParams
, 在这种情况下$routeParams.redirectParams
并使用$地点 http://docs.angularjs.org/api/ng.%24location将路线更改为/error
.
Spring 只是重定向到http://host:port/index.html/#/redirect/error=blabla
。您可以而且应该对此进行微调并支持多个routeParams。
在春天你基本上会有三个请求映射 http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/mvc.html:
- REST 请求映射 http://static.springsource.org/spring/docs/3.0.0.M3/reference/html/ch18s02.html
- index.html 请求映射
- 其他url请求映射
重定向所有其他请求:
@RequestMapping(value = "{path}", method = RequestMethod.GET)
public String redirect(@PathVariable String path) {
String route = null;
if (path.equals("/") || path.startsWith("/index.html")) {
// load index.html
} else {
route = "redirect:/index.html/#/redirect/" + path;
}
return route;
}