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
incorrect component passed to canDeactivate guard #34614
Comments
|
Just fyi this issue is present in Angular 9.1.0 as well: https://stackblitz.com/edit/angular-named-outlet-enygni?file=app%2Fapp.component.html |
…g two or more sibling router-outlets fixes angular#34614 There's an edge case where if I use two (or more) sibling <router-outlet>s in two (or more) child routes where their parent route doesn't have a component then preactivation will trigger all canDeactivate checks with the same component because it will use wrong OutletContext.
…g two or more sibling router-outlets (#36302) fixes #34614 There's an edge case where if I use two (or more) sibling <router-outlet>s in two (or more) child routes where their parent route doesn't have a component then preactivation will trigger all canDeactivate checks with the same component because it will use wrong OutletContext. PR Close #36302
|
Reopening - fix was reverted because it did not work with some configs. |
|
I guess this process with reverting commits can be improved a bit by reopening related issues to avoid some confusion |
|
I'm also experiencing the same issues, but my I found this bug in version 10.0.2 but was able to reproduce in latest 11.0.1 I believe my issue is related to the same as this ExpectedConsole should display following messages: Actual behaviourConsole only outputs: |
|
Having the same issue als @krilllind |
|
Seems to be still broken in Angular 13. I tried to fix it in #36302, but this PR was closed because it was supposed to be fix in another PR. However, that fix was reverted and I don't remember how I fixed it in #36302 because that's been two years already... |

Affected Package
The issue is caused by package @angular/routerDescription
For some reason CanDeactivate guard gets called with an incorrect component instance.
In this case it should get called with a component that is mounted in a named outlet, but gets called with one from primary outlet. See example in stackblitz.
I'd expect that with configuration like below:

The guard should only be called when
AdminHeaderComponentis being deactivated and only with this component instance.One notable thing is that the

currentRouteparam is correct!EDIT: found a workaround:
https://stackblitz.com/edit/angular-named-outlet-yfgsip?file=app%2Fadmin%2Fadmin.module.ts
adminlinkcreate userlinkNow click on

hide navbarlinkObserve that following messages are printed:
^ all good
adminandcreate userlinks againComponent 2I'd argue that the last message should state
AdminHeaderComponentAngular Version:
The text was updated successfully, but these errors were encountered: