Title: Unsubscribe from routing guards as soon as one of them returns false · Issue #36538 · angular/angular · GitHub
Open Graph Title: Unsubscribe from routing guards as soon as one of them returns false · Issue #36538 · angular/angular
X Title: Unsubscribe from routing guards as soon as one of them returns false · Issue #36538 · angular/angular
Description: 🚀 feature request Unsubscribe from routing guards as soon as one of them returns false For @angular/router Description Right now if you use two or more guards on a route, the router will run them all. Even if one of them already returned...
Open Graph Description: 🚀 feature request Unsubscribe from routing guards as soon as one of them returns false For @angular/router Description Right now if you use two or more guards on a route, the router will run them a...
X Description: 🚀 feature request Unsubscribe from routing guards as soon as one of them returns false For @angular/router Description Right now if you use two or more guards on a route, the router will run them a...
Opengraph URL: https://github.com/angular/angular/issues/36538
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unsubscribe from routing guards as soon as one of them returns false","articleBody":"# 🚀 feature request\r\n\r\nUnsubscribe from routing guards as soon as one of them returns false\r\n\r\nFor @angular/router\r\n\r\n### Description\r\n\r\nRight now if you use two or more guards on a route, the router will run them all. Even if one of them already returned false.\r\n\r\nPractical example: You have a checkout route:\r\n* Guard 1 checks, if you are logged in. If not, it shows the login\r\n* Guard 2 checks, if your address is missing. If it is, it redirects you to the page to enter an address\r\n* Guard 3 checks, if a payment is missing. If it is, it redirects you to the page to choose a payment method\r\n\r\nRoute looks like this:\r\n\r\n```typescript\r\n{\r\n path: '/checkout',\r\n canActivate: [LoginRequired, AddressRequired, PaymentRequired],\r\n}\r\n```\r\n\r\nIf you write it like that, and all 3 guards return false, you get 3 redirects. And if redirect `AddressRequired` wins, that routes `LoginRequired` will execute again.\r\n\r\nReproduction: https://ng-run.com/edit/uFlyQUYoejI0PkJhBUnm\r\nOpen the browser devtools console and then click the link to navigate to the blocked route to see the order of execution of the guards.\r\n\r\n### Describe the solution you'd like\r\n\r\nIf a guard returns false, unsubscribe from previous guards and don't even execute remaining guards.\r\n\r\nRight now we use a service that wraps the observables returned by canActivate to achieve this behavior. Looks like this https://ng-run.com/edit/HmMVqtmmHB52knus3yjk","author":{"url":"https://github.com/sod","@type":"Person","name":"sod"},"datePublished":"2020-04-09T10:18:42Z","url":"https://github.com/angular/angular/issues/36538"}
| 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:ec7d88d4-e007-678d-99cd-e648f4191b74 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C132:1EC9BC:A2A9B9:D0B10D:6B00F401 |
| html-safe-nonce | a7a049c3ceb05e4b4ba7ecfb9466b7126be907ebfa698a004fc9806c6ad2c68c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTMyOjFFQzlCQzpBMkE5Qjk6RDBCMTBEOjZCMDBGNDAxIiwidmlzaXRvcl9pZCI6IjgwODEzOTg2MTE4MzkwODc2MTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2bb960de07c62807d416df8ba10e01a776999cb719f228cefcbb091d534e4292 |
| hovercard-subject-tag | issue:597178259 |
| 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/36538/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ffa6cca374a8bf9b89bc4bfede64d32c27c559b5e923bfb1c6662f4e0d100c9d/angular/angular/issues/36538 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ffa6cca374a8bf9b89bc4bfede64d32c27c559b5e923bfb1c6662f4e0d100c9d/angular/angular/issues/36538 |
| og:image:alt | 🚀 feature request Unsubscribe from routing guards as soon as one of them returns false For @angular/router Description Right now if you use two or more guards on a route, the router will run them a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sod |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width