You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to override the back button behavior for certain routes in an Ionic Angular app with Capacitor, the Capacitor App App.addListener('backButton', callback) => doesn't override the back button so the user still navigates to the route.
This seems to occur in certain configurations and some it does not. For example, if I use the Ionic starter app "Build your first app" Photo taking app then the App.addListener('backButton', callback) => works correctly and allows blocking the back button for certain routes. However, I have another app that uses the same code and it doesn't prevent going back.
I believe it has to do with the built-in Ionic back button behavior and the order of it's listener and the listener added with App.addListener('backButton', callback) =>.
In my app, I am able to get it working by "manually" turning off the Ionic hardware button using config with IonicModule.forRoot({ hardwareBackButton: false }) following this Ionic Config docs. But I am confused why I have to manually do this in my app but not in the Ionic starter app.
I have 2 asks for this bug:
please indicate best practice when using Capacitor and Ionic with the back button. The addListener('backButton', ...) documentation mentions nothing about using ionic module configuration to enable taking over the backButton behavior and the Ionic Documentation for Angular says to use a different API this.platform.backButton.subscribeWithPriority(10, () =>
In the current versions of Ionic and Capacitor, which method should be used?
indicate in the addListener('backButton', ...) documentation that sometimes you may need to disable the Ionic default handler with IonicModule.forRoot({ hardwareBackButton: false })
Bug Report
When trying to override the back button behavior for certain routes in an Ionic Angular app with Capacitor, the Capacitor App
App.addListener('backButton', callback) =>
doesn't override the back button so the user still navigates to the route.This seems to occur in certain configurations and some it does not. For example, if I use the Ionic starter app "Build your first app" Photo taking app then the
App.addListener('backButton', callback) =>
works correctly and allows blocking the back button for certain routes. However, I have another app that uses the same code and it doesn't prevent going back.I believe it has to do with the built-in Ionic back button behavior and the order of it's listener and the listener added with
App.addListener('backButton', callback) =>
.In my app, I am able to get it working by "manually" turning off the Ionic hardware button using config with
IonicModule.forRoot({ hardwareBackButton: false })
following this Ionic Config docs. But I am confused why I have to manually do this in my app but not in the Ionic starter app.I have 2 asks for this bug:
this.platform.backButton.subscribeWithPriority(10, () =>
In the current versions of Ionic and Capacitor, which method should be used?
IonicModule.forRoot({ hardwareBackButton: false })
reference: (ionic-team/capacitor#2220 (comment))
Plugin(s)
App
Capacitor Version
Platform(s)
Ionic
Angular
Capacitor
Android
Current Behavior
In some cases the below code will not block the hardware back button from navigating back
Expected Behavior
The above code will prevent back navigation for certain routes.
The text was updated successfully, but these errors were encountered: