Title: NavigationExtras when returning URLTree from guard · Issue #27148 · angular/angular · GitHub
Open Graph Title: NavigationExtras when returning URLTree from guard · Issue #27148 · angular/angular
X Title: NavigationExtras when returning URLTree from guard · Issue #27148 · angular/angular
Description: 🚀 feature request Relevant Package This feature request is for @angular/router Description In #26521 (Angular 7.1.0), a feature was introduced that allows returning a URLTree from guards in order to initiate a redirect. However, this doe...
Open Graph Description: 🚀 feature request Relevant Package This feature request is for @angular/router Description In #26521 (Angular 7.1.0), a feature was introduced that allows returning a URLTree from guards in order t...
X Description: 🚀 feature request Relevant Package This feature request is for @angular/router Description In #26521 (Angular 7.1.0), a feature was introduced that allows returning a URLTree from guards in order t...
Opengraph URL: https://github.com/angular/angular/issues/27148
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"NavigationExtras when returning URLTree from guard","articleBody":"# 🚀 feature request\r\n\r\n### Relevant Package\r\nThis feature request is for @angular/router\r\n\r\n### Description\r\nIn #26521 (Angular 7.1.0), a feature was introduced that allows returning a `URLTree` from guards in order to initiate a redirect. However, this doesn't seem to allow using `NavigationExtras` such as `skipLocationChange`.\r\n\r\nSince the change in #26521 wasn't just syntax sugar, but is relevant to have predictable behavior when dealing with multiple guards, it should be considered to somehow allow using these options when returning a `URLTree` as well.\r\n\r\n### Describe the solution you'd like\r\nI don't have a really good proposal at this moment apart from next to returning `URLTree` also returning some kind of\r\n\r\n```\r\n// TODO: Find a better name?\r\ninterface NavigationOptions {\r\n urlTree: URLTree;\r\n navigationExtras: NavigationExtras;\r\n}\r\n```\r\n\r\nsuch that I could use\r\n\r\n```\r\nclass AwesomeGuard implements CanActivate {\r\n constructor(private router: Router) {}\r\n\r\n canActivate(): NavigationOptions | Observable\u003cNavigationOptions\u003e {\r\n return {\r\n urlTree: this.router.parseUrl(\"…\"),\r\n navigationExtras: {\r\n skipLocationChange: true,\r\n },\r\n };\r\n }\r\n}\r\n```\r\n\r\nI guess the exact typing of the guard would have to be\r\n\r\n```\r\n// Just a placeholder name\r\ntype GuardReturnType = boolean | URLTree | NavigationOptions;\r\n\r\ninterface CanActivate {\r\n canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): \r\n GuardReturnType \r\n | Promise\u003cGuardReturnType\u003e \r\n | Observable\u003cGuardReturnType\u003e\r\n}\r\n```\r\n\r\nAdmittedly, the return type of this function is growing increasingly complex with this.\r\n\r\n### Describe alternatives you've considered\r\nPossible options that I don't think would make good solutions would be\r\n\r\n* Returning an array `[URLTree, NavigationExtras]` (this just feels unclean)\r\n* Extending URLTree with the navigationExtras and extend parseUrl to take them as well (this muddies the entire API for a change in a specific location)","author":{"url":"https://github.com/Airblader","@type":"Person","name":"Airblader"},"datePublished":"2018-11-17T21:50:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":45},"url":"https://github.com/27148/angular/issues/27148"}
| 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:5dd1d164-ba9d-7581-7d37-a4129c951b74 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DF0A:3B1AF1:1379E1C:1C69D9B:6A6094C9 |
| html-safe-nonce | 97cfa17ad7a8cd4c911e58fe35ea9d2d45fc31684c2c5a05ec43ed74165cceb8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjBBOjNCMUFGMToxMzc5RTFDOjFDNjlEOUI6NkE2MDk0QzkiLCJ2aXNpdG9yX2lkIjoiNjkyODM1MTY4MTI5MTc4NTQxNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | df625fe7f6bffe08a06f8c2fe0289c1e8b7440be35ac45e12575af2aaa1804c5 |
| hovercard-subject-tag | issue:381904518 |
| 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/27148/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ebdd428ff83ebd0a821794dc0b408f91a12c5607407b61a721fecb8ac4ebaa7f/angular/angular/issues/27148 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ebdd428ff83ebd0a821794dc0b408f91a12c5607407b61a721fecb8ac4ebaa7f/angular/angular/issues/27148 |
| og:image:alt | 🚀 feature request Relevant Package This feature request is for @angular/router Description In #26521 (Angular 7.1.0), a feature was introduced that allows returning a URLTree from guards in order t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Airblader |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5142d23feb6a650085422edf60d68c93777dfa6c4b0c9151eb464d3e4969f618 |
| 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 | 6211071718785f6af328d66ee8cf4a7ce606987e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width