ionic 用户注销登录时,清空所有页面缓存
有人可能知道ionic的$ionicHistory是有一个清空缓存的命令的,命令如下:
clearHistory()
Clears out the app’s entire history, except for the current view.
但是此命令然并卵,所以我又看了一下API和源码发现了如下方法:
clearCache()
Removes all cached views within every ionNavView. This both removes the view element from the DOM, and destroy it’s scope.
- Returns: promise
/**
* @ngdoc method
* @name $ionicHistory#clearCache
* @return promise
* @description Removes all cached views within every {@link ionic.directive:ionNavView}.
* This both removes the view element from the DOM, and destroy it's scope.
*/
clearCache: function(stateIds) {
return $timeout(function() {
$ionicNavViewDelegate._instances.forEach(function(instance) {
instance.clearCache(stateIds);
});
});
},API地址:http://ionicframework.com/docs/api/service/$ionicHistory/
源码地址:https://github.com/driftyco/ionic/blob/master/js/angular/service/history.js#L1
然后写了如下代码去清空页面缓存:
var views = $ionicHistory.viewHistory().views;
var stateIds = [];
for(var id in views){
stateIds.push(views[id].stateId);
}
$ionicHistory.clearCache(stateIds).then(function(){
$location.path('/login');//设置路由地址
})
相关推荐
绿豆饼 2020-07-28
半纸药笺 2020-07-26
半纸药笺 2020-06-14
芯果科技蔡彦 2020-04-30
芯果科技蔡彦 2020-04-14
kfq00 2020-04-10
samllcat 2020-03-27
ZillahV0 2016-08-27
半纸药笺 2019-11-18
qixiang0 2015-04-24
shichong 2015-05-14
庆华 2015-12-26
genglang 2016-05-01
琪凡睿 2016-04-28
GoDotDotDot 2018-12-12
WarmPure 2018-10-02
青 2017-09-19
GoDotDotDot 2017-07-21