3

我正在尝试对应用程序中大多数路由的用户进行身份验证。

有没有办法在所有路线上在全球范围内做到这一点?所以我不需要以下内容:

resolve : {
    //This function is injected with the AuthService where you'll put your authentication logic
    'auth' : function(AuthService){
        return AuthService.authenticate();
    }
}

每次$routeProvider.when()通话。

4

1 回答 1

2

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
    });

}]);
于 2013-07-07T09:29:52.093 回答