Skip to content

bug: Angular Router fix in 11.2.10 breaks expected behavior for ion-router-outlet? #23230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
joshbowdoin opened this issue Apr 23, 2021 · 6 comments · Fixed by #23238
Closed
Labels
package: angular @ionic/angular package type: bug a confirmed bug report

Comments

@joshbowdoin
Copy link

joshbowdoin commented Apr 23, 2021

Bug Report

Ionic version:
[x] 5.x

Current behavior:
When using Angular >= 11.2.10 there is a change in the routing behavior due to this bug fix: issue: angular/angular#41379 | fix: atscott/angular@4f94113

With this bug fix, I can no longer navigate to routes parallel to ion-tabs routes and then use the ion-back-button to navigate back to my previous place in ion-tabs. It now always lands on the default tab.

Expected behavior:
Prior to fix, I was able to navigate from ion-tabs to parallel modules and then navigate back to previous location in ion-tabs.
Use case: app with Posts tab and Messages tab - both link to a separate Profile page, and should return to the original tab when "back" is clicked.

Steps to reproduce:
-- Expected Behavior: --
With this repo: https://github.com/joshbowdoin/back-button-test-angular_11.2.9
Navigate from Posts -> @UserHandle (profile page should show) -> click "Back" (should be back on Posts)
Navigate from Messages -> click a conversation -> click @UserHandle (profile page should show) -> click "Back" (should be on previous conversation

-- Broken Behavior: --
With this repo: https://github.com/joshbowdoin/back-button-test-angular_11.2.10
Navigate from Posts -> @UserHandle (profile page should show) -> click "Back" (should be back on Posts)
Navigate from Messages -> click a conversation -> click @UserHandle (profile page should show) -> click "Back" (broken: will now be on Posts instead of previous conversation)

Related code:
These three lines were added in Angular's deactivateRouteAndOutlet which destroys my previous context:
https://github.com/atscott/angular/blob/4f941133ce6bf551447c56b484a485261ea9bbfe/packages/router/src/operators/activate_routes.ts#L128-L130

      context.attachRef = null;
      context.resolver = null;
      context.route = null;

Ionic info:

Ionic:

   Ionic CLI                     : 6.13.1 (C:\Users\Cody\AppData\Roaming\npm\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 5.6.5
   @angular-devkit/build-angular : 0.1101.4
   @angular-devkit/schematics    : 11.1.4
   @angular/cli                  : 11.1.4
   @ionic/angular-toolkit        : 3.1.0

Capacitor:

   Capacitor CLI   : 2.4.7
   @capacitor/core : 2.4.7

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   NodeJS : v14.16.1 (C:\Program Files\nodejs\node.exe)
   npm    : 6.14.13
   OS     : Windows 10
@liamdebeasi
Copy link
Contributor

Thanks for the issue. I can reproduce this behavior. The problem here is that we attempt to save the route context inside of the tabs router outlet before it gets deactivated: https://github.com/ionic-team/ionic-framework/blob/master/angular/src/directives/navigation/ion-router-outlet.ts#L150

This line just creates a reference to the context object, but does not clone it. We later use that information to determine the correct URL to go back to (I.e. the correct tab): https://github.com/ionic-team/ionic-framework/blob/master/angular/src/directives/navigation/stack-controller.ts#L173-L182

Since we only created a reference to the context object, when Angular Router started clearing the old route information out in v11.2.10, we no longer had access to the route snapshot's URL to return us to the correct tab.

I created a patch that does a deep copy of the route object to preserve this snapshot URL so that we can retrieve it later.

Can you try the following dev build and let me know if it resolves the issue?

npm install @ionic/angular@5.7.0-dev.202104232151.a9018a2

@liamdebeasi liamdebeasi added package: angular @ionic/angular package type: bug a confirmed bug report labels Apr 23, 2021
@StavM
Copy link

StavM commented Apr 25, 2021

@liamdebeasi your temp package seems to solve the issue.

@avidan-chen
Copy link

@liamdebeasi any idea when this fix can be integrated in a stable version? @StavM and I are working on the same project, and we need this fix for our next release.

@joshbowdoin
Copy link
Author

@liamdebeasi Yes, your fix takes care of the problem in our app. Thanks so much for the quick work on this!

@liamdebeasi
Copy link
Contributor

Thanks for the issue. This has been resolved via #23238, and a fix will be available in an upcoming release of Ionic Framework. We do not normally give estimates on when fixes will be released, but given the nature of this bug we do plan on making a release this week.

@ionitron-bot
Copy link

ionitron-bot bot commented May 26, 2021

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators May 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: angular @ionic/angular package type: bug a confirmed bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants