Just to be clear, what’s your goal? You’ve got a page where you want to display a back button in some conditions and in others you want to display the hamburger menu button or you have a another goal?
Ionic 4 has a back button that is shown automatically when a page has been “pushed”. When that is visible I want to hide the menu button, otherwise you get the two next to each other which looks weird. This is a common pattern on Android. Hamburger menu on top-level activity, but when an activity is pushed a back button is shown in its place.
If your goal is the one I describe, what is really automatic in v3? I have that behavior and already in v3 I was managing it by my own.
You had me thinking I was crazy but I just created a new Ionic 3 project based on the “sidemenu” template and it definitely does this automatically. If I go to the “List” page (top-level) the hamburger menu is shown. If I click one of the list items from there another List page is pushed and the back button is shown in place of the hamburger menu. The NavBar automatically shows the back button when a page is pushed and the menuToggle (by default) automatically hides when it’s not on the root page. I’m trying to get the same behavior in Ionic 4.
What I do is I pass a param to my view, if param is
false I display the back button and if
true I display the menu (“ngIf” in the template)
That’d definitely be a work-around but since the back-button component is already doing this magic it seems silly to go through passing that around all over the place. NavParams are deprecated for v4 and it doesn’t make sense as a route/query param since that’s more application state than navigation. I could make a service that basically does the same thing as NavParams but it makes more sense to tap into whatever logic that back button is already using.