I have tried both $locationChangeStart
and $routeChangeStart
, but none of them work - they either cause flickering (switchign urls) or don't work at all. what am I doing wrong here?
$rootScope.$on('$locationChangeStart', function (event,future,current) {
if (!user.isAuthenticated()){
$location.path('/login');
event.preventDefault();
}
});
$rootScope.$on('$routeChangeStart', function() {
if (!user.isAuthenticated()) {
$location.path('/login');
}
});
see this punker http://plunker.co/edit/SnBuFPXSLMBd8G9R0KXl?p=preview