I am having issue when i try to logout and perform a location.path('/') to homepage.
Below is my code,
angular.module('MyApp')
.controller('LogoutCtrl', function($location, $auth,$rootScope) {
if (!$auth.isAuthenticated()) { return; }
$auth.logout()
.then(function() {
$auth.logout();
$rootScope.user='';
$location.path('/');
});
});
my app.js for this calling is :
.state('login.logout', {
url: '/logout',
template: null,
controller: 'LogoutCtrl'
})
I found that it is not redirecting when I perform the logout action in the same state. Which is http://localhost:8000/#/
But it will work when I'm in different state. Any guidance pls?
1.your using state provider, so whenever you want to redirect page using url need to use like $location.url('/'); if you want to use path then u need to pass state name as parameter for $location $location.path('/page/login'); here '/page/login' is your login or whatever page you want to redirect that page state.
尝试:
window.location.href = "/";
I highly recommend you use ui-router for your redirects as well. Have a 'home' state point to the '/' url
.state('Home', {
url: '/',
....
})
and then just do something like
$auth.logout()
.then(function() {
// do your cleanup
return $state.go('Home');
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.