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.

Allow to reset tab navigation stack on changing tabs.

See original GitHub issue

Feature Request

Ionic version: [x] 4.x

Describe the Feature Request Allow to reset tab view stack on changing tabs.

Currently ion-tabs navigation on changing the tab to one selected in the past having some sub views opened brings back the the most recent view for this tab.

Describe Preferred Solution in some cases restoring view stack may be confusing to the user - thus there should be an option to reset the tab to the root component.

also both ionTabsWillChange and ionTabsDidChange are called just one after another emitting same new tab while I’d expect to be able to know also the leaving tab (add leavingTab property to the event?).

finally ionTabsWillChange is fired only after the new tab is already visible while I’d expect to get ionTabsWillChange before activating new tab and only ionTabsWillChange after (this probably can be a separate bug)

Describe Alternatives

if there is a way to achieve this without side effect - would be good to add this information to the documentation.

Related Code

Additional Context

here is similar concern from another person on SO: https://stackoverflow.com/questions/53687233/how-to-reset-route-stack-after-routing-away-from-tab-using-angular-ionic-4#comment96962743_53687233

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:26
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
gaetancollaudcommented, Oct 29, 2020

Hi, with Ionic 5, my dirty solution is to directly use the router:

  // Tabs that need reset when you click on them
  resetStackTabs = ['koalas'];

  @ViewChild('tabs') tabs: IonTabs;

  constructor(private router:Router) {
  }

  handleTabClick = (event: MouseEvent) => {
    const {tab} = event.composedPath().find((element: any) =>
      element.tagName === 'ION-TAB-BUTTON') as EventTarget & { tab: string };

    if (this.resetStackTabs.includes(tab)){
      this.router.navigate(['tabs/'+tab]);
    }
  };
<ion-tab-button tab="koalas" (click)="handleTabClick( $event)">
8reactions
leoruhlandcommented, Apr 18, 2019

Hey @ciekawy!

I think I have a temporary solution that does not seem to have any side-effects (yet).

<ion-tabs #tabs>
    <ion-tab-button tab="tab1" (click)="openTab('tab1', $event)">
        <ion-label>Tab</ion-label>
    </ion-tab-button>
</ion-tabs> 
@ViewChild('tabs') tabs: IonTabs;

async openTab(tab: string, evt: MouseEvent) {
    const tabSelected = this.tabs.getSelected();
    evt.stopImmediatePropagation();
    evt.preventDefault();
    return tabSelected !== tab
      ? await this.navCtrl.navigateRoot(this.tabs.outlet.tabsPrefix + '/' + tab)
      : this.tabs.select(tab);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to reset tab stack when you come back to a tab from ...
This approach resets any stack navigation within a tab when the tab index changes. This also makes sure the active stack is not...
Read more >
React Navigation v5: Reset Stack Inside Tab After Leaving Tab
Problem: You have a stack navigator inside a tab and, when going to a different tab, you want to reset the stack navigator...
Read more >
React Native Navigation with Switch, Stack and Tab - Medium
Switch Navigation : This allows user to navigate between screens. It can only load one screen at a time. There is no back...
Read more >
gui design - iOS Global Tab Bar Navigation
Users can reset the state when they tap on the tab they're currently on. This however is unknown to some users. There are...
Read more >
Combining Stack Navigation with Tab Navigation in React ...
So, we create stack navigator in each page of the tabs, so that you can go to the details screen through the help...
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