0
Ok, ich versuche, eine Standortänderung zu verhindern, wenn Token nicht den Anforderungen entspricht. Ich habe einfach Code, die ich in .run
Stufe verwenden:(route | location) ChangeStart preventDefault
.run(['$location','$rootScope','$http',
function($location, $rootScope, $http)
{
$rootScope.$on('$routeChangeStart', function(event, next){
var nextPath = next.$$route.originalPath;
if (nextPath != '/login'){
var token = localStorage.getItem('token');
$http({
method: 'GET',
url: '/token',
headers: {
'auth-token': token
}
}).then(function(data){
$location.url(nextPath);
}, function(err){
event.preventDefault(); //can't prevent here
// $location.path('/login'); //this works perfectly but couse unneeded location change
})
}
})
}])
Lage ändern kann weder mit locationChangeStart noch mit routeChangeStart