question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: IonRouterOutlet canGoBack() return always return false

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
DwieDimacommented, Jun 2, 2022

I took a closer look at the problem and it seems that routerOutlet always fetches the next parent instance of ion-router-outlet from the respective page. So if we call routerOutlet.canGoBack() inside app.component.ts, the value would always be false because ion-tabs have their own ion-router-outlet.

Thats why using this.routerOutlet.canGoBack() inside childpages of ion-tabs will 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:

@ViewChild(IonTabs, { static: true }) private ionTabs: IonTabs;
...
constructor(
  private platform: Platform,
) {
  this.platform.backButton.subscribeWithPriority(-1, () => {
    if (!this.ionTabs.outlet.canGoBack()) {
      App.exitApp();
    }
  });
}

It’s important that you handle the logic inside tabs.page.ts since we use the Viewchild of ion-tabs, which contains the outlet for tabbed pages.

0reactions
mellunarcommented, Jun 30, 2022

@derWebdesigner still returning always false

Read more comments on GitHub >

github_iconTop Results From Across the Web

bug: IonRouterOutlet canGoBack() return always return false ...
canGoBack() can change and ngOnInit() is called once; ngOnInit() is called before the page is even part of the outlet and the transition...
Read more >
Ionic Android Platform BackButton Issue
Bug Report Ionic version: [x] 4.6.1 / 4.6.2 Current behavior: ActivatedRoute canGoBack() always return false Expected behavior: canGoBack() ...
Read more >
How to get canGoBack functionality in Ionic 5? - Stack Overflow
If set to false, then it means it is dynamic and not static, and router outlet should be static since its one of...
Read more >
canGoBack always return false - Ionic Forum
hello all i have i ion-tabs page as a root page , and in my app.component.ts a i register a backbuttonAction for showing...
Read more >
@ionic/core | Yarn - Package Manager
All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines. 6.3.10 (2022-12-07). Bug Fixes. datetime: ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found