Title: Router initializer never completes if initial navigation fails · Issue #44355 · angular/angular · GitHub
Open Graph Title: Router initializer never completes if initial navigation fails · Issue #44355 · angular/angular
X Title: Router initializer never completes if initial navigation fails · Issue #44355 · angular/angular
Description: Which @angular/* package(s) are relevant/releated to the feature request? router Description Rendering an app in SSR (using nguniversal) with an invalid URL (e.g. http://localhost:4200/electronics-spa/en/USD/Brands/Canon/c/brand_10 or%...
Open Graph Description: Which @angular/* package(s) are relevant/releated to the feature request? router Description Rendering an app in SSR (using nguniversal) with an invalid URL (e.g. http://localhost:4200/electronics-...
X Description: Which @angular/* package(s) are relevant/releated to the feature request? router Description Rendering an app in SSR (using nguniversal) with an invalid URL (e.g. http://localhost:4200/electronics-...
Opengraph URL: https://github.com/angular/angular/issues/44355
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Router initializer never completes if initial navigation fails","articleBody":"### Which @angular/* package(s) are relevant/releated to the feature request?\r\n\r\nrouter\r\n\r\n### Description\r\n\r\nRendering an app in SSR (using nguniversal) with an invalid URL (e.g. http://localhost:4200/electronics-spa/en/USD/Brands/Canon/c/brand_10%20or%20(1,2)=(select*from(select%20name_const(CHAR(82,88,106,99,113,78,74,70,73,118,87),1),name_const(CHAR(82,88,106,99,113,78,74,70,73,118,87),1))a)%20--%20and%201%3D1) causes the render to hang, and never release the taken resources.\r\n\r\nThe reason is that the navigation never completes on error, when the `Router` option `initialNavigation` is set to `enabled`.\r\n\r\n### Proposed solution\r\n\r\nExpose `RouterInitializer`.\r\nEDIT: or make the router complete the navigation on error, if that makes sense.\r\n\r\n### Alternatives considered\r\n\r\nWe came up with this _workaround_, but it would be nice if `ɵangular_packages_router_router_h` could be exposed.\r\n\r\n```ts\r\nimport { Injectable, Injector, Provider } from '@angular/core';\r\nimport {\r\n NavigationError,\r\n Router,\r\n ROUTER_CONFIGURATION,\r\n ɵangular_packages_router_router_h as RouterInitializer,\r\n} from '@angular/router';\r\nimport { filter, take } from 'rxjs/operators';\r\n\r\n@Injectable()\r\nexport class CustomRouterInitializer extends RouterInitializer {\r\n appInitializer(): Promise\u003cany> {\r\n const injector: Injector = (this as any).injector;\r\n const opts = injector.get(ROUTER_CONFIGURATION);\r\n\r\n if (\r\n opts.initialNavigation ===\r\n 'enabled' /* for Ng11: || opts.initialNavigation === 'enabledBlocking' */\r\n ) {\r\n let resolve: any;\r\n const res = new Promise((r) => (resolve = r));\r\n\r\n injector\r\n .get(Router)\r\n .events.pipe(\r\n // We want to explicitly react on NavigationError event occurs just\r\n // after the first navigation start event\r\n take(2),\r\n filter((event) => event instanceof NavigationError)\r\n )\r\n .subscribe(() => resolve(false));\r\n\r\n super.appInitializer().then((val) => resolve(val));\r\n return res;\r\n }\r\n\r\n return super.appInitializer();\r\n }\r\n}\r\n\r\nexport const routerFixProvider: Provider = {\r\n provide: RouterInitializer,\r\n useClass: CustomRouterInitializer,\r\n};\r\n```\r\n\r\nThe above workaround is for ng12. \r\nI noticed that in ng13 there's no similar private API available, unless I'm missing something.","author":{"url":"https://github.com/znikola","@type":"Person","name":"znikola"},"datePublished":"2021-12-02T21:49:31Z","url":"https://github.com/angular/angular/issues/44355"}
| 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:5dff8eb4-fb56-aad4-b17b-cfda430c8162 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D9C4:27E5CD:BA5F8C:F1D73D:6B00EC5A |
| html-safe-nonce | 28845bfd0282d2f6fd30baa4df2d2e52d42a8631556f51e1e97e2185f944beb5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOUM0OjI3RTVDRDpCQTVGOEM6RjFENzNEOjZCMDBFQzVBIiwidmlzaXRvcl9pZCI6IjQ0NjgzNDUxMzMxNDU4NDQ4MjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d0c1694b7c792c6c874c32f693d5341cfc48acdac44cb7e340ae7e94120a81f0 |
| hovercard-subject-tag | issue:1070011544 |
| 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/44355/issue_layout |
| twitter:image | https://opengraph.githubassets.com/894ed971f039014473cb4e091df16efef6e1b4a7b253e6af8e802cec274f8b63/angular/angular/issues/44355 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/894ed971f039014473cb4e091df16efef6e1b4a7b253e6af8e802cec274f8b63/angular/angular/issues/44355 |
| og:image:alt | Which @angular/* package(s) are relevant/releated to the feature request? router Description Rendering an app in SSR (using nguniversal) with an invalid URL (e.g. http://localhost:4200/electronics-... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | znikola |
| 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