In my app, I require to check the user details, in case if the user is not logged in, then i require to redirect back to /login page. but my try is not working, where should I do this config?
my try :
(function(){
"use strict";
angular.module('meanOffice')
.config(routeConfig)
.run(stateController);
function routeConfig( $locationProvider, $stateProvider, $urlRouterProvider ){
$stateProvider
.state('login', {
url:'/',
templateUrl : 'app/views/pages/login/login.html',
controller : 'mainController as main'
})
.state('users', {
url:'/users',
templateUrl : 'app/views/pages/users/users.html',
controller : 'usersController as users',
required : true,
resolve : {
usersData : function(){
return "Arif";
}
}
})
$urlRouterProvider.otherwise('/');
}
function stateController( $rootScope, auth, authToken ){
$rootScope.$on('$routeChangeStart', function(){
var isLoggedIn = auth.isLoggedIn();
//but each time the route change, this is not called..!?
if( !isLoggedIn )
$location.path('/');
});
}
})();