Disable hardware back button in Ionic framework


Disable hardware back button in Ionic framework : Sometimes we need to to disable back button in ionic application. You can use event.preventDefault() to prevent the hardware back button click. Here in this tutorial we are going to explain the functionality how you can disable the back button in ionic framework.


Disable hardware back button in Ionic framework

You can disable the back button simply as below –

Disable hardware back button in Ionic framework:

<scritp type="text/javascript">
$ionicPlatform.registerBackButtonAction(function (event) {
                    event.preventDefault();
            }, 100);
</script>

This will prevent the default back button action.

If you want to disable the back button for some state you can use the following method to disable the back button functionality only for that state. In this case back button will work as normally except the specified state.

Disable hardware back button in Ionic framework:

<scritp type="text/javascript">
$ionicPlatform.registerBackButtonAction(function (event) {
 //if specified state matches else go back
  if ($ionicHistory.currentStateName() === 'some_state_name'){
    event.preventDefault();
  } else {
    $ionicHistory.goBack();
  }
            }, 100);
</script>

This will prevent the default back button action.


Advertisements

Add Comment

📖 Read More