Can't get out of ionic

Hi I have a problem with ion input and logout.

Each time after logging out, I can click the "Back" button and it will return me to the previous page. Can I know how to clear or delete a session when I log out so that the user cannot return to the 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 that the user is logged in

 $localstorage.set('loggin_state', '1'); 
+5
source share
3 answers

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 found out that adding a little delay allows $ionicHistory clear the cache.

 $ionicHistory.nextViewOptions({ disableBack: true, historyRoot: true }); 
  • disableBack . The following representation should forget about its reverse representation and set it to null.
  • historyRoot . The following view should be the root view in its history stack.
+14
source

$ionicHistory.clearCache() now returns a promise, so you can guarantee that the cache is cleared. So you can do 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, for example.

loan goes

+4
source

This is because ionic caches the view so that it will stop the ion transition through the controller.

Thus, you can overload the cache as follows

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

read here for more details

+2
source

Source: https://habr.com/ru/post/985030/


All Articles