本文介绍了不能从离子注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有离子登录和注销的问题。

注销后每一次,我还可以点击后退按钮,它会带我回到我的previous页面。可我知道如何清除或删除会话时注销,使用户无法从登录回到previous页?

  VAR default_stat;
$ scope.logout =功能(){
    $ ionicLoading.show({模板:注销....'});
    $ localstorage.set('loggin_state','');
    $ state.go('登录');
    $ ionicLoading.hide();
    $ ionicHistory.clearHistory();
    $ ionicHistory.clearCache();
};

在登录时我使用localStorage的指示用户已登录

  $ localstorage.set('loggin_state','1');


解决方案

我会做这样的事情:

  $ scope.logout =功能(){
    $ ionicLoading.show({模板:注销....'});
    $ localstorage.set('loggin_state','');    $超时(函数(){
        $ ionicLoading.hide();
        $ ionicHistory.clearCache();
        $ ionicHistory.clearHistory();
        $ ionicHistory.nextViewOptions({disableBack:真的,historyRoot:真});
        $ state.go('登录');
        },30);};

我发现,加入少许延迟允许 $ ionicHistory 来清除缓存。

  $ ionicHistory.nextViewOptions({disableBack:真的,historyRoot:真});


  • disableBack:下一个视图应该忘记它的背面图,并将其设置为null

  • historyRoot:下一个视图应该成为历史堆栈中的根视图

Hi I have an issue with ionic login and logout.

Each time after logout, i can still click the back button and it will bring me back to my previous page. may i know how to clear or delete session when logout so that user unable to go back to previous page from the login?

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

during login i use localstorage to indicate user has logged in

$localstorage.set('loggin_state', '1');
解决方案

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.

这篇关于不能从离子注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 14:56