我正在使用Ionic v1 Angular
这是我的代码:
$scope.back = function () {
$ionicHistory.goBack();
// window.history.back(); //this works but not working on device hardware back button
console.log($ionicHistory.currentView()); //url: app/home
console.log($ionicHistory.backView()); //url: app/home
};
这是我的按钮:
<button ng-hide="current_state == 'app.home'" class="button button-clear" menu-toggle="left" ng-click="back()" id="back_button">back</button>
答案 0 :(得分:1)
如果要控制硬件按钮,则必须注册并覆盖硬件后退按钮的默认操作
// Disable BACK button on home
$ionicPlatform.registerBackButtonAction(function (event) {
if($state.current.name=="app.home"){ // if you are in home page you can close the app
navigator.app.exitApp();
}
else { // otherwise you just go back to previous statein the history
navigator.app.backHistory();
}
}, 100);