gpt4 book ai didi

javascript - $ionicHistory.clearHistory 清除历史记录,但在 android 上单击 hardwareBackButton 时会转到上一个 View ?

转载 作者:行者123 更新时间:2023-12-03 09:10:56 30 4
gpt4 key购买 nike

这是我的代码

.controller("HomeCtrl", function ($scope,$ionicHistory,SearchService) {

$scope.history = $ionicHistory.viewHistory();
$scope.clearhistory = function(){
$ionicHistory.clearHistory();
$scope.history = $ionicHistory.viewHistory();
}

})


.state('eventmenu.home', {
url: "/home",
cache: false,
views: {
'menuContent' :{
templateUrl: "templates/home.html",
controller: "HomeCtrl"
}
}
})
ion-view title='<a href="#/event/home"><img class="title-image" src="img/acc.png" height = "40px" width = "120px"/></a>'>
<ion-content class="padding" ng-hide="searchBarVisibility">
<pre>{{history | json}}</pre>
<button ng-click="clearhistory()">clear</button>
</ion-content>
</ion-view>

我的应用程序中的同一 View 中有 10 个状态。第 10 个状态有一个到主页的链接。当我通过第 10 个状态进入主页时,{{history}} 显示遍历的所有状态,当我按下清除按钮时,所有历史记录也会被清除,我得到以下输出。

    "histories": {
"root": {
"historyId": "root",
"parentHistoryId": null,
"stack": [],
"cursor": -1
},
"ion1": {
"historyId": "ion1",
"parentHistoryId": "root",
"stack": [
{
"viewId": "ion33",
"index": 1,
"historyId": "ion1",
"backViewId": null,
"forwardViewId": null,
"stateId": "eventmenu.home",
"stateName": "eventmenu.home",
"url": "/event/home",
"canSwipeBack": true,
"title": "&lt;a href=\"#/event/home\"&gt;&lt;img class=\"title-image\" src=\"img/acc.png\" height = \"40px\" width = \"120px\"/&gt;&lt;/a&gt;"
}
],
"cursor": -1
},
"ion5": {
"historyId": "ion5",
"parentHistoryId": "root",
"stack": [],
"cursor": -1
}
},
"views": {
"ion33": {
"viewId": "ion33",
"index": 1,
"historyId": "ion1",
"backViewId": null,
"forwardViewId": null,
"stateId": "eventmenu.home",
"stateName": "eventmenu.home",
"url": "/event/home",
"canSwipeBack": true,
"title": "&lt;a href=\"#/event/home\"&gt;&lt;img class=\"title-image\" src=\"img/acc.png\" height = \"40px\" width = \"120px\"/&gt;&lt;/a&gt;"
}
},
"backView": null,
"forwardView": null,
"currentView": {
"viewId": "ion33",
"index": 1,
"historyId": "ion1",
"backViewId": null,
"forwardViewId": null,
"stateId": "eventmenu.home",
"stateName": "eventmenu.home",
"url": "/event/home",
"canSwipeBack": true,
"title": "&lt;a href=\"#/event/home\"&gt;&lt;img class=\"title-image\" src=\"img/acc.png\" height = \"40px\" width = \"120px\"/&gt;&lt;/a&gt;"
}

但是当我点击android的硬件按钮时,问题就出现了。应用程序再次遍历之前访问过的所有状态,而不是退出应用程序。并且当它返回到主页时,历史堆栈再次被填充。即使历史记录已被清除,为什么还会发生这种情况?如果历史记录被清除,我应该如何使应用程序在单击后退按钮后退出。

最佳答案

 $ionicPlatform.registerBackButtonAction(function () {
if ($state.current.name == "signIn"){
navigator.app.exitApp();
} else {
navigator.app.backHistory();
}
}, 100);

作为引用,请查看blogspot在注册后退按钮操作下,如果您有任何疑问,请回复我

关于javascript - $ionicHistory.clearHistory 清除历史记录,但在 android 上单击 hardwareBackButton 时会转到上一个 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32072225/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com