AngularJS | handle routing before they load

后端 未结 5 1078
我在风中等你
我在风中等你 2020-12-07 17:10

I wish to create a simple authentication check for my routes by external service.

I define the access requirements on the route object:

$routeProvide         


        
5条回答
  •  孤街浪徒
    2020-12-07 17:41

    Angularjs resolve example:

    .when('/profile', {
            templateUrl: 'views/profile.html',
            controller: 'ProfileCtrl',
            resolve: {
                app: function($q, $rootScope, $location) {
                    var defer = $q.defer();
                    if ($rootScope.currentUser == undefined) {
                        $location.path('/login');
                    };
                    defer.resolve();
                    return defer.promise;
                }
            }
    

提交回复
热议问题