Disable hardware back button in Ionic application?

后端 未结 8 1049
暗喜
暗喜 2020-12-24 13:21

I\'m trying to disable the back button on my Cordova app. I\'m using AngularJS + Ionic Framework. I found topics about this and tried the code bellow, but it has absolutely

8条回答
  •  渐次进展
    2020-12-24 13:54

    To expand upon David D's answer I have included the go back implementation.

    Put this in your applications .run function:

    $ionicPlatform.registerBackButtonAction(function (event) {
      if ($ionicHistory.currentStateName() === 'someStateName'){
        event.preventDefault();
      } else {
        $ionicHistory.goBack();
      }
    }, 100);
    

    This will not work in controllers, it is application wide.

提交回复
热议问题