I recently started working with Ionic and encountered an issue with the onHardwareBackButton event. The event is functioning properly and directing me to the register function, but even after going to the register function, it still navigates back to the previous page. I have a Cordova confirm dialog box set up in the hardwarebackbutton event function so that when the user clicks cancel, they can navigate back to the previous page. However, now the popup appears simultaneously with the navigation back. I have tried various solutions like using:
e.preventDefault()
e.stopPropagation()
but unfortunately, neither of them worked for me. I also attempted to use the registerBackButtonAction event, but it doesn't deregister when I leave the page. I have been stuck on this issue for hours. Below is the code snippet I am currently using:
// Registering the event
showAlertPopup = function(){
// Show the popup
}
$scope.$on '$ionicView.enter', (event, view)->
$ionicPlatform.registerBackButtonAction showalertPopup, 100
// Deregistering the event
$scope.$on '$ionicView.leave', (event, view)->
$ionicPlatform.offHardwareBackButton showalertPopup
Instead of registerBackButtonAction, I have tried using onHardwareBackButton.