我正在服务器端进行身份验证和授权。
在 angularJs 中,我正在使用这样的routeProvider 进行路由。
$routeProvider.
when('/', {
templateUrl: 'partials/_home',
controller: 'HomeCtrl'
}).
when('/home', {
templateUrl: 'partials/_home',
controller: 'HomeCtrl'
}).
when('/users', {
templateUrl: 'partials/_users',
controller: 'UserCtrl'
}).
when('/users/:id', {
templateUrl: 'partials/_userForm',
controller: 'UserCtrl'
}).
otherwise({
redirectTo: '/'
});
这里是要解决的问题,当我收到 403 Angular 未显示服务器页面时,它只是不执行任何操作。
有人对如何处理这个问题有建议吗?
最佳答案
AngularJS 拦截器 - 更新至 v1.4.2
The interceptors are service factories that are registered with the $httpProvider by adding them to the $httpProvider.interceptors array. The factory is called and injected with dependencies (if specified) and returns the interceptor.
了解更多信息:$http angularjs Doc
部分配置(部分)
.config(function ($httpProvider) {
$httpProvider.interceptors.push('responseObserver');
})
响应 - 观察者工厂
403.html
和 500.html
是现有的 HTML 文件,样式漂亮,并为用户提供了一些帮助内容。
.factory('responseObserver', function responseObserver($q, $window) {
return {
'responseError': function(errorResponse) {
switch (errorResponse.status) {
case 403:
$window.location = './403.html';
break;
case 500:
$window.location = './500.html';
break;
}
return $q.reject(errorResponse);
}
};
});
扩展有关拦截器的知识:http://djds4rce.wordpress.com/2013/08/13/understanding-angular-http-interceptors/
关于javascript - AngularJs RouteProvider http 状态 403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25041929/