ionic-framework: bug: IonRouterOutlet canGoBack() return always return false
Bug Report
Ionic version:
[x] 4.6.1 / 4.6.2
Current behavior:
ActivatedRoute canGoBack() always return false
Expected behavior:
canGoBack() should return correctly
Steps to reproduce:
Related code:
insert short code snippets here
Other information:
Ionic info:
insert the output from ionic info here
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 8
- Comments: 18 (5 by maintainers)
I took a closer look at the problem and it seems that routerOutlet always fetches the next parent instance of
ion-router-outletfrom the respective page. So if we callrouterOutlet.canGoBack()insideapp.component.ts, the value would always befalsebecauseion-tabshave their ownion-router-outlet.Thats why using
this.routerOutlet.canGoBack()inside childpages ofion-tabswill return the correct boolean value.If you need to handle something globally (like using android hardware backbutton to exit app) you can use following snippet:
It’s important that you handle the logic inside
tabs.page.tssince we use theViewchildofion-tabs, which contains the outlet for tabbed pages.