ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
51.1k stars 13.5k forks source link

bug: angular, ion-back-button not going back to correct tab after leaving main tabs context #19801

Open andreas-aeschlimann opened 5 years ago

andreas-aeschlimann commented 5 years ago

Bug Report

Ionic version:

[x] 4.x

Current behavior:

When you navigate from a tab page to another tab page and then go back with the ion-back-button, you will always end up at tab index 0 of the first tab page.

Expected behavior:

Instead, the app should go back to the tab where the user came from.

Steps to reproduce:

To illustrate the problem, I have taken the sample starter tab app of Ionic and extended it with a second tab page. This is the setup:

First tab page (TabsPage):

Second tab page (OtherTabsPage):

Reproduce the problem like this:

Related code:

You can easily try it out here:

https://stackblitz.com/edit/ionic-v4-angular-tabs-hxxnpm

Ionic info:

Ionic:

   Ionic CLI                     : 5.4.4 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.11.2
   @angular-devkit/build-angular : 0.803.15
   @angular-devkit/schematics    : 8.3.15
   @angular/cli                  : 8.3.15
   @ionic/angular-toolkit        : 2.1.1

Capacitor:

   Capacitor CLI   : 1.3.0
   @capacitor/core : 1.3.0

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : none
   Cordova Plugins   : no whitelisted plugins (0 plugins total)

Utility:

   cordova-res : not installed
   native-run  : 0.2.8 (update available: 0.2.9)

System:

   ios-deploy : 1.9.2
   ios-sim    : 8.0.1
   NodeJS     : v10.16.0 (/usr/local/bin/node)
   npm        : 6.12.1
   OS         : macOS Mojave
   Xcode      : Xcode 11.0 Build version 11A420a
indraraj26 commented 4 years ago

Bump any news on this?

Zapominacz commented 3 years ago

I wonder if deep view checking will help with this issue: In the StackController class, we are determining the back url in the pop method by:

const view = views[views.length - deep - 1];
let url = view.url; 
const viewSavedData = view.savedData;

I tried to replace the code above with:

let view = views[views.length - deep - 1];
let viewSavedData = view.savedData;
while (viewSavedData.get('primary')) {
  view = viewSavedData.get('primary').outlet.stackCtrl.activeView;
  viewSavedData = view.savedData;
}
let url = view.url;

And it properly fixed the issue in #23218

Do I miss something here?

Zapominacz commented 3 years ago

Ok, nevermind. Version 5.6.6 fixes that issue