使用$ http然后重定向AngularJS注销

时间:2016-09-29 09:20:38

标签: php angularjs laravel angular-ui-router

是的,所以我在这里有一点困境:)。

我正在开发一个用angularjs和Laravel构建的项目。我应该说,使用laravel完成登录,这是laular的AngularJs“范围”。

所以在前端我看不到那个页面。

我要做的是使用$ http get方法来获取/注销(再次由laravel处理)。成功时将用户重定向到/ login。

所以我想做的是:

$rootScope.logout = function () {

        $http.get('/logout', function (response) {
            console.log('redirect');
            $window.location.href('/login');
        });
    };

但由于某种原因似乎没有效果。建议? / logout清除所有会话等,这是我的“管辖权”:)

顺便说一下,我也在使用UI路由器。

1 个答案:

答案 0 :(得分:0)

location.replace应解决您的问题。

$rootScope.logout = function () {

    $http.get('/logout', function (response) {
        console.log('redirect');
        var origin = $window.location.origin;
        $window.location.replace(origin + '/login');
    });
};

更新: 如果您已为注销页面定义了路由。

$ rootScope.logout = function(){

    $http.get('/logout', function (response) {
        console.log('redirect');
        $state.go('logout');
    });
};

但请记住,在这种情况下你应该有logout状态。