Ion-back-button vs browser back button Ionic 4


#1

Is it true that the angular navigation stack differs from the browser, or is there something else going on.
I’ve started an Ionic v4 angular app with tabs, and moved home, contact, about and tabs to an newly created folder. After everything working, I ran ionic g page pages/settings/theme to generate a page to switch themes. So it’s basically a subpage of settings (http://localhost:4200/tabs/(settings:settings)), but the route is http://localhost:4200/theme. I use the router this.router.navigate([${route}]);, where route is the pages name. When using the browsers back button on that page, i get send back to the settings page (Wanted behaviour) but when I’m using the <ion-back-button> on that same page, i’m getting send back to the root (http://localhost:4200/tabs/(home:home)). I think it’s the behavior of the browsers history vs the angular navigation stack, but I’m not completely sure.
What do I need to do to make Ion back button go back to the settingspage, or how do I make the theme page a real child of settings for that matter ?

Thanks for your brains in advance!

Nathan


#2

setRoot should do the job (if you build an angular app)


#3

Hi Nathan did you find any solution?


#5

I just hardcode the backroute inside the back button like this:

    <ion-buttons slot="start">
      <ion-back-button  defaultHref="/tabs/(settings:settings)"></ion-back-button>
    </ion-buttons>

I foresee problems when opening a certain page via push messages, back button should then just close the app but this way that wont happen. But I don’t see myself using any functions like that in the near future so it isn’t a issue for me now.