无法退出离子

dav*_*lee 5 angularjs ionic-framework angular-local-storage

嗨我有离子登录和注销的问题.

每次注销后,我仍然可以单击后退按钮,它将返回到我的上一页.我可以知道如何在注销时清除或删除会话,以便用户无法从登录返回上一页吗?

var default_stat;
$scope.logout = function(){
    $ionicLoading.show({template:'Logging out....'});
    $localstorage.set('loggin_state', '');
    $state.go('login');
    $ionicLoading.hide();
    $ionicHistory.clearHistory();
    $ionicHistory.clearCache();
};
Run Code Online (Sandbox Code Playgroud)

在登录期间,我使用localstorage来指示用户已登录

$localstorage.set('loggin_state', '1');
Run Code Online (Sandbox Code Playgroud)

Lef*_*tyX 14

我会做这样的事情:

$scope.logout = function(){
    $ionicLoading.show({template:'Logging out....'});
    $localstorage.set('loggin_state', '');

    $timeout(function () {
        $ionicLoading.hide();
        $ionicHistory.clearCache();
        $ionicHistory.clearHistory();
        $ionicHistory.nextViewOptions({ disableBack: true, historyRoot: true });
        $state.go('login');
        }, 30);

};
Run Code Online (Sandbox Code Playgroud)

我发现添加一点延迟可以$ionicHistory清除缓存.

$ionicHistory.nextViewOptions({ disableBack: true, historyRoot: true });
Run Code Online (Sandbox Code Playgroud)
  • disableBack:下一个视图应该忘记它的后视图,并将其设置为null.
  • historyRoot:下一个视图应该成为其历史堆栈中的根视图.


Tan*_*eer 5

$ionicHistory.clearCache()现在返回promise,以便您可以确保清除缓存.所以你可以像这样打电话:

$ionicHistory.clearCache().then(function() {
    //now you can clear history or goto another state if you need
    $ionicHistory.clearHistory();
    $ionicHistory.nextViewOptions({ disableBack: true, historyRoot: true });
    $state.go('login');
})
Run Code Online (Sandbox Code Playgroud)

没有必要像上面这样的超时.

信用去