我正在尝试为我的应用程序中的大多数路由验证用户。
有没有办法在所有路线上全球完成?所以我不需要以下内容:
resolve : {
//This function is injected with the AuthService where you'll put your authentication logic
'auth' : function(AuthService){
return AuthService.authenticate();
}
}
每次$routeProvider.when()
来电。
答案 0 :(得分:2)
现在我采取了一种更简单的方法:
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
});
}]);