首页 文章

离子防止硬件返回上一页

提问于
浏览
1

我试图通过硬件后退按钮阻止回到上一页使用这个:

$ionicPlatform.onHardwareBackButton(function () {
    if($state.$current.name=="authentication") {
        $ionicPopup.confirm({
            title: 'System warning',
            template: 'Are you sure you want to exit?'
        }).then(function(res){
           if( res ){
              navigator.app.exitApp();
           }
        })
    }
});

但它不起作用 . 出现警告弹出框时,它仍会返回上一页 .

我怎么能阻止它?

1 回答

  • 0

    你可以试试这个,

    .run(function($ionicPlatform, $ionicPopup) {
      $ionicPlatform.registerBackButtonAction(function(event) {
        if (true && $state.$current.name=="authentication") { // your check here
          $ionicPopup.confirm({
            title: 'System warning',
            template: 'are you sure you want to exit?'
          }).then(function(res) {
            if (res) {
              ionic.Platform.exitApp();
            }
          })
        }
      }, 100);
    });
    

相关问题