can't logout from ionic

牧云@^-^@ 提交于 2019-11-30 21:19:51

I would do something like this:

$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);

};

I've found out that adding a little delay allow $ionicHistory to clear the cache.

$ionicHistory.nextViewOptions({ disableBack: true, historyRoot: true });
  • disableBack: The next view should forget its back view, and set it to null.
  • historyRoot: The next view should become the root view in its history stack.

$ionicHistory.clearCache() now returns promise so you can ensure cache is cleared. So you can call like this:

$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');
})

There is no need for the above timeout like things.

credit goes to

This is because ionic is caching the view, So that will stop ionic going through the controller.

So you could bust the cache as follows

<ion-view cache-view="false" view-title="My Title!">
  ...
</ion-view> 

read here for more

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!