Title: UrlMatcher as a service · Issue #17145 · angular/angular · GitHub
Open Graph Title: UrlMatcher as a service · Issue #17145 · angular/angular
X Title: UrlMatcher as a service · Issue #17145 · angular/angular
Description: I'm submitting a ... (check one with "x") [ ] bug report => search github for a similar issue or PR before submitting [x] feature request [ ] support request => Please do not submit support request here, instead see https://github.com/an...
Open Graph Description: I'm submitting a ... (check one with "x") [ ] bug report => search github for a similar issue or PR before submitting [x] feature request [ ] support request => Please do not submit support request...
X Description: I'm submitting a ... (check one with "x") [ ] bug report => search github for a similar issue or PR before submitting [x] feature request [ ] support request => Please do not su...
Opengraph URL: https://github.com/angular/angular/issues/17145
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"UrlMatcher as a service","articleBody":"\u003c!--\nIF YOU DON'T FILL OUT THE FOLLOWING INFORMATION WE MIGHT CLOSE YOUR ISSUE WITHOUT INVESTIGATING\n-->\n\n**I'm submitting a ...** (check one with \"x\")\n```\n[ ] bug report => search github for a similar issue or PR before submitting\n[x] 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**\nOnly a function can be set as the `urlMatcher` of a route.\n\n```\nconst routes = [{\n urlMatcher: (segments: UrlSegment[], segmentGroup: UrlSegmentGroup, route: Route) => {\n /* Do stuff */\n },\n component: MyComponent,\n}]\n```\n\n**Expected behavior**\nA DI-resolved service or function can be set as the `urlMatcher` allowing for further injection. I'd expect this to work in an identical way to how the resolver properties can either be services that implement the `Resolve\u003cT>` interface OR can be an inline `resolve()` function.\n\n```\nconst routes = [{\n urlMatcher: MyUrlMatcherService,\n component: InterruptComponent,\n},\n{\n path: \":id\",\n component: ListComponent, /* Contains a \u003crouter-outlet> for routing children */ \n children: [ /*children with sub-paths for deep linking */ ]\n}];\n\n@Injectable()\nexport class MyUrlMatcherService {\n constructor(myStateService:MyStateService){}\n\n matchUrl(segments: UrlSegment[], segmentGroup: UrlSegmentGroup, route: Route):UrlMatchResult {\n if (!this.myStateService.isInterrupt) return null;\n /* Do matching stuff */\n }\n}\n```\n\n**Minimal reproduction of the problem with instructions**\nN/A\n\n**What is the motivation / use case for changing the behavior?**\nMy use case is that `InterruptComponent` should resolve if some system state (managed by a service) is currently true. If not, I want to skip this route an let other routes attempt matching. In my case I want to greedily consume the entire sub-path and display a specific component, but only in certain circumstances.\n\n**Please tell us about your environment:** \nN/A\n\n* **Angular version:** 4.X\n* **Browser:** N/A\n* **Language:** TypeScript 2.2+ \n* **Node (for AoT issues):** N/A","author":{"url":"https://github.com/PleasantD","@type":"Person","name":"PleasantD"},"datePublished":"2017-05-31T20:13:40Z","url":"https://github.com/angular/angular/issues/17145"}
| 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:09bf9047-0180-8167-3bbc-1a37075a1ecb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AEA0:2E124E:7AC6A4:9E27B7:6B00E812 |
| html-safe-nonce | ed3bb3e406f06cc0b9e32a4dcddfd77c65510faa0e1ad779f427a72475a53c67 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUEwOjJFMTI0RTo3QUM2QTQ6OUUyN0I3OjZCMDBFODEyIiwidmlzaXRvcl9pZCI6IjQ3MjAzNjUxNDI1MzYxNTMxMDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d5a1dd67c7c05e577a61b583a8c1468e2a1d059263c8ebcbfc97e8081b39d08e |
| hovercard-subject-tag | issue:232681968 |
| 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/17145/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2108caa46d3b844ea1f584159e70b4335e9ee2a4552ac56e375c3b17840fd99c/angular/angular/issues/17145 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2108caa46d3b844ea1f584159e70b4335e9ee2a4552ac56e375c3b17840fd99c/angular/angular/issues/17145 |
| og:image:alt | I'm submitting a ... (check one with "x") [ ] bug report => search github for a similar issue or PR before submitting [x] feature request [ ] support request => Please do not submit support request... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | PleasantD |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width