Title: Can Activate child, can Activate operational order · Issue #10845 · angular/angular · GitHub
Open Graph Title: Can Activate child, can Activate operational order · Issue #10845 · angular/angular
X Title: Can Activate child, can Activate operational order · Issue #10845 · angular/angular
Description: [x] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#...
Open Graph Description: [x] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support request here, instead see https://github.com/angu...
X Description: [x] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support request here, instead see https://github.co...
Opengraph URL: https://github.com/angular/angular/issues/10845
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Can Activate child, can Activate operational order ","articleBody":"```\n[x] bug report => search github for a similar issue or PR before submitting\n[ ] feature request\n[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\n```\n\n**Current behavior**\n\nThe canActivate guard on the child component is called before the canActivateChild guard on the parent. \n\nROUTER_CONFIG\n\n``` js\n{\n path: ':tenant',\n canActivateChild: [TenantGuard], //** This is called second **\n children: [\n {\n path: 'component-foo',\n component: EmployeeSearch,\n canActivate: [AuthGuard] //**This is called first **\n }\n]\n}\n```\n\nThis is because canActivate is before canActivateChild in the check guards array. \n\n`[this.runCanActivate(s.route), this.runCanActivateChild(s.path)]`\n\nrouter.ts\n\n``` js\n checkGuards(): Observable\u003cboolean> {\n if (this.checks.length === 0) return Observable.of(true);\n return Observable.from(this.checks)\n .map(s => {\n if (s instanceof CanActivate) {\n return andObservables(\n Observable.from([this.runCanActivate(s.route), this.runCanActivateChild(s.path)]));\n } else if (s instanceof CanDeactivate) {\n // workaround https://github.com/Microsoft/TypeScript/issues/7271\n const s2 = s as CanDeactivate;\n return this.runCanDeactivate(s2.component, s2.route);\n } else {\n throw new Error('Cannot be reached');\n }\n })\n .mergeAll()\n .every(result => result === true);\n }\n```\n\n**Expected/desired behavior**\n\nI feel that the parent guard should be called and prevent transition before the child guard is called. \n\n**What is the motivation / use case for changing the behavior?**\n\nMy specific use case is that I have a parent route from which I want to, get, validate and set a tenant for use by child components and services.\n\nThen I want to check the user is authenticate on some of the child routes. My big issue is that my AuthGuard depends on the tenant having been set by the TenantGuard on the parent route.\n\nGenerically though I feel it makes more logical sense that a parent guard is checked before the child guard is checked \n\nHappy to fix this and update tests (pull request) if you are happy with an order swap.\n\n`[this.runCanActivateChild(s.path), this.runCanActivate(s.route)]`\n\n**Please tell us about your environment:**\n- **Angular version:** 2.0.0-rc.5\n- **Browser:** [all ] \n - **Language:** [TypeScript 1.8.10] \n","author":{"url":"https://github.com/vespertilian","@type":"Person","name":"vespertilian"},"datePublished":"2016-08-16T09:58:28Z","url":"https://github.com/angular/angular/issues/10845"}
| 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:c90a3f0a-ee78-8acc-07b3-81fe7e3f3948 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8B5E:363D8E:16E739A:1D2B0F2:6B01229C |
| html-safe-nonce | 0f0a6d2f4b00759838f6fdf89b9f3214d502cc6f66d230ead4b939b84e029db3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QjVFOjM2M0Q4RToxNkU3MzlBOjFEMkIwRjI6NkIwMTIyOUMiLCJ2aXNpdG9yX2lkIjoiMTM4MjQ1MzUyNjU5MjAzNzUzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0a816c6550ca7b54964b9e89419fc948195cc741324003d6c04d8774865f5e41 |
| hovercard-subject-tag | issue:171370230 |
| 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/10845/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3e86457129fdc720c41abaf607035542d26d90e4033a580530df97f0e53afe81/angular/angular/issues/10845 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3e86457129fdc720c41abaf607035542d26d90e4033a580530df97f0e53afe81/angular/angular/issues/10845 |
| og:image:alt | [x] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support request here, instead see https://github.com/angu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vespertilian |
| 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