Title: incorrect component passed to canDeactivate guard · Issue #34614 · angular/angular · GitHub
Open Graph Title: incorrect component passed to canDeactivate guard · Issue #34614 · angular/angular
X Title: incorrect component passed to canDeactivate guard · Issue #34614 · angular/angular
Description: 🐞 bug report Affected Package The issue is caused by package @angular/router Description For some reason CanDeactivate guard gets called with an incorrect component instance. In this case it should get called with a component that is mou...
Open Graph Description: 🐞 bug report Affected Package The issue is caused by package @angular/router Description For some reason CanDeactivate guard gets called with an incorrect component instance. In this case it should...
X Description: 🐞 bug report Affected Package The issue is caused by package @angular/router Description For some reason CanDeactivate guard gets called with an incorrect component instance. In this case it should...
Opengraph URL: https://github.com/angular/angular/issues/34614
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"incorrect component passed to canDeactivate guard ","articleBody":"\u003c!--🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅\r\n\r\nOh hi there! 😄\r\n\r\nTo expedite issue processing please search open and closed issues before submitting a new one.\r\nExisting issues often contain information about workarounds, resolution, or progress updates.\r\n\r\n🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅-->\r\n\r\n\r\n# 🐞 bug report\r\n\r\n### Affected Package\r\n\u003c!-- Can you pin-point one or more @angular/* packages as the source of the bug? -->\r\n\u003c!-- ✍️edit: --> The issue is caused by package @angular/router\r\n\r\n\r\n### Description\r\n\r\nFor some reason CanDeactivate guard gets called with an incorrect component instance.\r\nIn 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.\r\n\r\nI'd expect that with configuration like below:\r\n\r\nThe guard should only be called when `AdminHeaderComponent` is being deactivated and only with this component instance.\r\n\r\nOne notable thing is that the `currentRoute` param is correct!\r\n\r\n\r\n\r\nEDIT: found a workaround:\r\n```\r\ncanDeactivate(component: HasComponentPendingChanges, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot) {\r\n if (currentRoute.outlet === OVERLAY_OUTLET && this.router['rootContexts'] && this.router['rootContexts'].getContext) {\r\n const context: OutletContext = this.router['rootContexts'].getContext(OVERLAY_OUTLET);\r\n if (context && context.outlet && context.outlet.isActivated && context.outlet['activated'].instance) {\r\n component = context.outlet['activated'].instance;\r\n }\r\n }\r\n```\r\n\r\n## 🔬 Minimal Reproduction\r\n\u003c!--\r\nPlease create and share minimal reproduction of the issue starting with this template: https://stackblitz.com/fork/angular-issue-repro2\r\n-->\r\n\r\nhttps://stackblitz.com/edit/angular-named-outlet-yfgsip?file=app%2Fadmin%2Fadmin.module.ts\r\n\r\n\r\n- Open the link\r\n- Open the console\r\n- Click on `admin` link\r\n- Click on `create user` link\r\n- Observe that following message is printed:\r\n```\r\ndeactivating UsersListComponent {}\r\n```\r\n- Now click on `hide navbar` link\r\n\r\n\r\n- Observe that following messages are printed:\r\n```\r\ndeactivating CreateUserComponent {}\r\ndeactivating AdminHeaderComponent {}\r\n```\r\n^ all good\r\n- Now the fun begins, click on `admin` and `create user` links again\r\n- Click on `Component 2`\r\n- Observe that following messages are printed:\r\n```\r\ndeactivating UsersListComponent {}\r\ndeactivating CreateUserComponent {}\r\ndeactivating CreateUserComponent {}\r\n```\r\nI'd argue that the last message should state `AdminHeaderComponent`\r\n\r\n## 🌍 Your Environment\r\n\r\n**Angular Version:**\r\n\u003cpre>\u003ccode>\r\n8.2.14\r\n\u003c/code>\u003c/pre>\r\n\r\n\r\n","author":{"url":"https://github.com/FDIM","@type":"Person","name":"FDIM"},"datePublished":"2020-01-02T15:28:51Z","url":"https://github.com/angular/angular/issues/34614"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:26755f18-42c6-fee6-4aa5-e2002a0becf4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ED12:34CAB:1B7E661:2312063:6B015A5B |
| html-safe-nonce | f838d65af8c5bc49c5732876bf4e60ff95b5020cd99e9eeba96baf63a4bbad94 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRDEyOjM0Q0FCOjFCN0U2NjE6MjMxMjA2Mzo2QjAxNUE1QiIsInZpc2l0b3JfaWQiOiIyODYxNDM3ODI0MzQ1OTIyMTM5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 67f958b4c8b777e41804c2b78ff40bdc676b209524c0b98385661cc71ce45746 |
| hovercard-subject-tag | issue:544624529 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/34614/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8912382bd377f136a1041e72672189871ad9cf9cd2955996348a675254019204/angular/angular/issues/34614 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8912382bd377f136a1041e72672189871ad9cf9cd2955996348a675254019204/angular/angular/issues/34614 |
| og:image:alt | 🐞 bug report Affected Package The issue is caused by package @angular/router Description For some reason CanDeactivate guard gets called with an incorrect component instance. In this case it should... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | FDIM |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width