当我按back按钮时,如何使用AngularJS在注销后重定向到登录页面。
我尝试了下面的代码来重定向相同的页面。
AuthenticationService.ClearCredentials();
$state.go('login', null, {reload: true});发布于 2018-07-26 03:15:33
有很多方法可以做到这一点。为此,首选的方法是使用$routeChangeStart。这将检查每次应用程序重定向到不同页面时的登录状态。
angular.module('myApp')
.run(['$rootScope','$location', 'AuthenticationService', function ($rootScope, $location, AuthenticationService) {
$rootScope.$on('$routeChangeStart', function (event) {
//Here, you may need to add a function isLoggedIn() to your service which will tell used logged in status
if (!AuthenticationService.isLoggedIn()) {
console.log('User not loged in, hence no access of this page');
event.preventDefault();
$location.path('/login');
}
else {
console.log('Redirect to page');
}
});
}])只需在服务中添加一个函数,检查用户是否为loggedIn及以上用户即可工作。我希望这能帮到你
https://stackoverflow.com/questions/51472230
复制相似问题