Title: canActivate=>false can result in blank screen/dead link · Issue #16211 · angular/angular · GitHub
Open Graph Title: canActivate=>false can result in blank screen/dead link · Issue #16211 · angular/angular
X Title: canActivate=>false can result in blank screen/dead link · Issue #16211 · angular/angular
Description: I'm submitting a ... (check one with "x") [ X ] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support request here, instead see https://github.com/...
Open Graph Description: I'm submitting a ... (check one with "x") [ X ] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support reque...
X Description: I'm submitting a ... (check one with "x") [ X ] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not ...
Opengraph URL: https://github.com/angular/angular/issues/16211
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"canActivate=>false can result in blank screen/dead link","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[ X ] bug report => search github for a similar issue or PR before submitting\n[ ] 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**\n\u003c!-- Describe how the bug manifests. -->\ncanActivate, canActivateChild will result in NavigationCancel event if 'false'/reject() happens in the Guard. Additionally the URL is reset to the base path before the navigation attempt (as though to leave the user on the page they navigated from).\n\nThis current behavior means that if you just go directly to a location in your browser (e.g. localhost:4200/some-guarded-route) and it returns false the URL will read \"localhost:4200/\" with a blank page as navigation is canceled.\n\n**Expected behavior**\n\u003c!-- Describe what the behavior would be without the bug. -->\nThe right behavior to me seems that the router should try to see if there are further matches in the routing table (i.e. the guard 'false' case would cover the use case scenario of #14515). By continuing down the route table the behavior would be to land on '**' route in the worst case while also enabling conditional routing.\n\nMinimally NavigationCancel event should determine if the resetUrlToCurrentUrlTree is an already displayed route (either rendering it if necessary or doing nothing if it's already rendered).\n\nI will see if I can issue a PR to fix this for review. Will need to determine what the side effects would be for cases where people would expect just to stay on the currently rendered page (considering it was already rendered). However, to me I think the correct behavior for a dead link should be to go down the route table and hit '**' for a 404 or something vs doing nothing when the user clicks on it and rendering nothing if the user hits the route directly before any route has been rendered.\n\n**Minimal reproduction of the problem with instructions**\n\u003c!--\nIf the current behavior is a bug or you can illustrate your feature request better with an example, \nplease provide the *STEPS TO REPRODUCE* and if possible a *MINIMAL DEMO* of the problem via\nhttps://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).\n-->\n\nPlunker won't work for this because you would need to be able to hit the route as though it was bookmarked to reproduce.\n\nEffectively just create project using CLI, create a route guard, return false in the methods. Then attempt to hit the route directly without loading a root non-guarded route first.\n\n\n**What is the motivation / use case for changing the behavior?**\n\u003c!-- Describe the motivation or the concrete use case -->\n\nMotivation is that you won't have the user on a blank screen if they happen to hit a guarded route without meeting the conditions.\n\nSecond part is that by resolving these scenarios by continuing down the route table you would enable conditional routing for scenarios such as:\n\nCreating routes like:\nlocalhost:4200/:organization\nlocalhost:4200/:user\n\nIf the route guard found a valid organization it could allow the request to move forward vs user. This is all gravy. A start is to not give the user a blank page when resetting the route via resetUrlToCurrentUrlTree when the current Url wasn't rendered in the first place.\n\n**Please tell us about your environment:**\n\u003c!-- Operating system, IDE, package manager, HTTP server, ... -->\nMac OS Sierra (10.12.4), WebStorm, NPM, ng serve\n\n* **Angular version:** Angular 4.0.2\n\u003c!-- Check whether this is still an issue in the most recent Angular version -->\n\n\n* **Browser:** Chrome 57\n\u003c!-- All browsers where this could be reproduced -->\n\n \n* **Language:** TypeScript 2.2.2\n\n* **Node (for AoT issues):** `node --version` = \nNode 7.9","author":{"url":"https://github.com/matthewerwin","@type":"Person","name":"matthewerwin"},"datePublished":"2017-04-20T19:21:40Z","url":"https://github.com/angular/angular/issues/16211"}
| 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:1c97a947-0ef7-916d-c7c6-0a2010c1f694 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8F30:2C4BED:80AAC6:A52971:6B00E7DA |
| html-safe-nonce | 960d69bd6ac31c8c94e21b168d3edd8ae39cd51612d84010709d9917995ad7e0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RjMwOjJDNEJFRDo4MEFBQzY6QTUyOTcxOjZCMDBFN0RBIiwidmlzaXRvcl9pZCI6IjM1MDQzOTA3NDM0NzUxNTI4NTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1d1513b18faac6470533380b1ce1f387c30bb8f49bad81c881a239106936dbed |
| hovercard-subject-tag | issue:223171991 |
| 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/16211/issue_layout |
| twitter:image | https://opengraph.githubassets.com/32cd3a4e12f335b6f2154e023fe58b40f1b16d69c9117dff11b86268c5a4f61e/angular/angular/issues/16211 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/32cd3a4e12f335b6f2154e023fe58b40f1b16d69c9117dff11b86268c5a4f61e/angular/angular/issues/16211 |
| og:image:alt | I'm submitting a ... (check one with "x") [ X ] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support reque... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | matthewerwin |
| 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