I'm trying to log the user's action of clicking the generated back button in the navigation bar, but I can't find a way to handle the click event?
It seems like the ion-nav-back-button from here isn't working anymore?
I'm trying to log the user's action of clicking the generated back button in the navigation bar, but I can't find a way to handle the click event?
It seems like the ion-nav-back-button from here isn't working anymore?
In case someone is still having a problem after using
@ViewChild(Navbar) navBar: Navbar;
try NOT to put the
this.navbar.backButtonClick
in theconstructor()
Alternatively, you can place it at
ionViewDidLoad()
it should work.If you want too do it manually:
Add this to your
page.html
Add in your page.ts file:
You need first to add
hideBackButton
to theion-navbar
. It will remove the default back button.Then you add your own button that you can easily manage with a click event.
THE CODE:
Final thing: Css.
The icon will be smaller than the usual back button. If you want to make it similar to the default one used in Ionic2 you need to increase its size.
For customize default back button action you need override the backButtonClick() method of the NavBar component.
In your "customClass.ts" import Navbar component. Create auxMethod for override the default behavior and called in your ionViewDidLoad method.
This code has been tested in ionic 3.
According to the official Ionic docs, you can override the
backButtonClick()
method of the NavBar component:In case anyone is looking. Ionic 3 offers life-cycle events. Either "ionViewDidLeave" or "ionViewWillLeave" can be used for such purposes.
Check out docs to see more events. https://ionicframework.com/docs/api/navigation/NavController/