Created
March 9, 2014 06:11
-
-
Save kentcdodds/9443522 to your computer and use it in GitHub Desktop.
Angular-UI Router states auth/anon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$stateProvider. | |
state('main', { | |
abstract: true, | |
url: '/', | |
templateUrl: '/main/index.html', | |
controller: 'SuperCtrl', | |
resolve: { | |
isAuthenticated: function($q, $http) { | |
var deferred = $q.defer(); | |
$http.get('/api/v1/auth/isAuthenticated').then(function(response) { | |
deferred.resolve(response.data.isAuthenticated); | |
}, deferred.reject); | |
return deferred.promise; | |
} | |
}, | |
onEnter: function($state, isAuthenticated) { | |
$state.go('main.' + (isAuthenticated ? 'auth' : 'anon')); | |
} | |
}). | |
state('main.anon', { | |
url: '', | |
templateUrl: '/main/anon/index.html', | |
controller: 'FrontPageCtrl' | |
}). | |
state('main.auth', { | |
url: '', | |
templateUrl: '/main/index.html', | |
controller: 'MainCtrl' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment