Angularjs location.path 在同一状态下不起作用
Angularjs location.path on same state not working
我在尝试注销并执行 location.path('/') 到主页时遇到问题。
下面是我的代码,
angular.module('MyApp')
.controller('LogoutCtrl', function($location, $auth,$rootScope) {
if (!$auth.isAuthenticated()) { return; }
$auth.logout()
.then(function() {
$auth.logout();
$rootScope.user='';
$location.path('/');
});
});
我的 app.js 对于这个调用是:
.state('login.logout', {
url: '/logout',
template: null,
controller: 'LogoutCtrl'
})
我发现当我在相同状态下执行注销操作时,它没有重定向。这是 http://localhost:8000/#/
但它会在我处于不同状态时起作用。有什么指导吗?
尝试:
window.location.href = "/";
我强烈建议您也使用 ui-router 进行重定向。
有一个 'home' 状态指向 '/' url
.state('Home', {
url: '/',
....
})
然后做类似
的事情
$auth.logout()
.then(function() {
// do your cleanup
return $state.go('Home');
})
1.your 使用 state provider,所以每当你想使用 url 重定向页面时,都需要使用 like
$location.url('/');
如果你想使用路径,那么你需要将状态名称作为 $location 的参数传递
$location.path('/page/login');
这里“/page/login”是您的登录名或您想要重定向该页面状态的任何页面。
我在尝试注销并执行 location.path('/') 到主页时遇到问题。
下面是我的代码,
angular.module('MyApp')
.controller('LogoutCtrl', function($location, $auth,$rootScope) {
if (!$auth.isAuthenticated()) { return; }
$auth.logout()
.then(function() {
$auth.logout();
$rootScope.user='';
$location.path('/');
});
});
我的 app.js 对于这个调用是:
.state('login.logout', {
url: '/logout',
template: null,
controller: 'LogoutCtrl'
})
我发现当我在相同状态下执行注销操作时,它没有重定向。这是 http://localhost:8000/#/
但它会在我处于不同状态时起作用。有什么指导吗?
尝试:
window.location.href = "/";
我强烈建议您也使用 ui-router 进行重定向。 有一个 'home' 状态指向 '/' url
.state('Home', {
url: '/',
....
})
然后做类似
的事情$auth.logout()
.then(function() {
// do your cleanup
return $state.go('Home');
})
1.your 使用 state provider,所以每当你想使用 url 重定向页面时,都需要使用 like $location.url('/'); 如果你想使用路径,那么你需要将状态名称作为 $location 的参数传递 $location.path('/page/login'); 这里“/page/login”是您的登录名或您想要重定向该页面状态的任何页面。