【问题标题】:AngularJS authenticating multiple routes with resolveAngularJS 通过解析验证多个路由
【发布时间】:2013-07-04 11:00:03
【问题描述】:
我正在尝试对应用程序中大多数路由的用户进行身份验证。
有没有办法在所有路线上全局执行此操作?所以我不需要以下内容:
resolve : {
//This function is injected with the AuthService where you'll put your authentication logic
'auth' : function(AuthService){
return AuthService.authenticate();
}
}
在每个$routeProvider.when() 通话中。
【问题讨论】:
标签:
javascript
php
angularjs
model-view-controller
url-routing
【解决方案1】:
Gloopy 的建议非常有趣,我将来可能会实施类似的方法。
现在我采取了一种更简单的方法:
gm.config(['$routeProvider', 'PathProvider', function($routeProvider, PathProvider) {
var authResolver = { // although this does work there could be a better way to do this.
'auth' : function(AuthenticationService) {
return AuthenticationService.isLoggedIn();
}
};
$routeProvider.when('/authenticatedRoute', {
templateUrl: PathProvider.view('application/dashboard/index.html'),
controller: 'dashboardController',
resolve: authResolver
});
$routeProvider.otherwise({
redirectTo: '/dashboard',
resolve: authResolver
});
}]);