Title: Consider populating the router.config…children array the same for static and lazy loaded routes · Issue #40010 · angular/angular · GitHub
Open Graph Title: Consider populating the router.config…children array the same for static and lazy loaded routes · Issue #40010 · angular/angular
X Title: Consider populating the router.config…children array the same for static and lazy loaded routes · Issue #40010 · angular/angular
Description: 🚀 feature request Relevant Package This feature request is for @angular/router Description Consider populating the router.config…children array the same for static and lazy loaded routes. Describe the solution you'd like Some developers ...
Open Graph Description: 🚀 feature request Relevant Package This feature request is for @angular/router Description Consider populating the router.config…children array the same for static and lazy loaded routes. Describe ...
X Description: 🚀 feature request Relevant Package This feature request is for @angular/router Description Consider populating the router.config…children array the same for static and lazy loaded routes. Describe ...
Opengraph URL: https://github.com/angular/angular/issues/40010
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Consider populating the router.config…children array the same for static and lazy loaded routes","articleBody":"# 🚀 feature request\r\n\r\n### Relevant Package\r\nThis feature request is for @angular/router\r\n\r\n### Description\r\nConsider populating the router.config…children array the same for static and lazy loaded routes.\r\n\r\n### Describe the solution you'd like\r\n\r\nSome developers including myself like to create navigation elements, say for a header component, directly from the router.confg. Everything is already populated in the router config (including custom data and access via a RouteGuard). When using static routes I would normally do something like the following.\r\n\r\n```\r\n this.items = this.router.config\r\n .find((route: Route) => {\r\n return route.path === this.routePath\r\n })\r\n ?.children\r\n .filter((route: Route) => {\r\n return route.data != null \r\n })\r\n .map((route: Route, index) => {\r\n return {\r\n path: \"/\" + this.routePath + \"/\" + route.path,\r\n icon: route.data.icon,\r\n label: route.data.label\r\n }\r\n });\r\n```\r\n\r\nThe code above simply creates an object array called items for the children of a specific route. I am not showing all the detail but just focusing on the children array because these are static routes. The object returned can be anything the developer needs. \r\n\r\nNow when using lazy loaded routes the children array is not available because the routing data is stored in lazy loaded modules that have not been loaded yet. Several people have tried to use the private _loadedConfig property on a route but it gets ugly and you end up with something like this.\r\n\r\n```\r\n this.buttons = (this.router.config\r\n .find((route: Route) => {\r\n return route.path === this.routePath\r\n }) as any)\r\n ?._loadedConfig\r\n ?.routes[0]\r\n ?.children\r\n .filter((route: Route) => {\r\n return route.data != null \r\n })\r\n .map((route: Route, index: number) => {\r\n return {\r\n path: \"/\" + this.routePath + \"/\" + route.path,\r\n icon: route.data.icon,\r\n label: route.data.label,\r\n }\r\n })\r\n```\r\n\r\nWhile this works its not ideal. The obvious issue is that the private _loadedConfig is subject to change without warning in the future because its not part of the public API and this object is not available until some point in the lifecycle that I have not been able to determine yet. \r\n\r\nNow the data that is eventually available in the _loadedConfig is exactly what developers are interested in (path, data, etc.) and it seems to be available even before the lazy modules are loaded. Given this would it be possible to present this information using the normal children array regardless if it’s a static route or a lazy loaded route? In most scenarios developers only care to have access to the route children and its less important that it’s from a static route vs. a lazy loaded route. A Boolean or enumeration could be added that would let the developer know the route static vs lazy if that is important. \r\n\r\nThis would mean any code designed to work with the router, config, and children would work with static or lazy loaded routes. The project could start with standard static routes and then later be reconfigured to use lazy routes and any code already in place that leverages the router config would continue to work.\r\n\r\nOne additional thought would be at webpack/compile time Angular would have access to all the routes regardless if they are static or lazy. Maybe some metadata can be derived from this and used to populate the routes children information at runtime.\r\n \r\nI know it’s a long shot, but I wanted to suggest the general idea.\r\n\r\nThanks,\r\nEric\r\n\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/epaitz","@type":"Person","name":"epaitz"},"datePublished":"2020-12-07T17:48:49Z","url":"https://github.com/angular/angular/issues/40010"}
| 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:f6553b59-55a5-2532-aba2-6b46ee6c507d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C26E:25A204:E50E47:12E7D6B:6B00FE03 |
| html-safe-nonce | 2de1257d55fd27ba905f4bbbacb3f00cfe19e5b5c845d095bb9956300d1ef1c4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjZFOjI1QTIwNDpFNTBFNDc6MTJFN0Q2Qjo2QjAwRkUwMyIsInZpc2l0b3JfaWQiOiI4MjEyODQ0NDY2NzMwNDk5NTg4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bb1f676bf6b91cb8290cd842f3fe7b06d76bbf6810159578dcd644e84a56c4dd |
| hovercard-subject-tag | issue:758715620 |
| 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/40010/issue_layout |
| twitter:image | https://opengraph.githubassets.com/06fc76e0db5d743a32affe7ca003b8f3a5123164658f0f340f4167d63ced4bd5/angular/angular/issues/40010 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/06fc76e0db5d743a32affe7ca003b8f3a5123164658f0f340f4167d63ced4bd5/angular/angular/issues/40010 |
| og:image:alt | 🚀 feature request Relevant Package This feature request is for @angular/router Description Consider populating the router.config…children array the same for static and lazy loaded routes. Describe ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | epaitz |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| 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 | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width