Title: CanRender Feature - Not to render a router link in the first place - Automatically · Issue #12499 · angular/angular · GitHub
Open Graph Title: CanRender Feature - Not to render a router link in the first place - Automatically · Issue #12499 · angular/angular
X Title: CanRender Feature - Not to render a router link in the first place - Automatically · Issue #12499 · angular/angular
Description: I'm submitting a ... [ ] 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/angular/angular/blob/m...
Open Graph Description: I'm submitting a ... [ ] 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 h...
X Description: I'm submitting a ... [ ] bug report => search GitHub for a similar issue or PR before submitting [x ] feature request [ ] support request => Please do not submit support request here, ins...
Opengraph URL: https://github.com/angular/angular/issues/12499
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"CanRender Feature - Not to render a router link in the first place - Automatically","articleBody":"**I'm submitting a ...**\r\n\r\n```\r\n[ ] bug report => search GitHub for a similar issue or PR before submitting\r\n[x ] feature request\r\n[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\r\n```\r\n\r\n**Current behavior**\r\n\r\n\u003c!-- Describe how the bug manifests. -->\r\n\r\nA router is mostly self-aware and can also guard itself via one or more helper services. What if the route never renders itself via `routerLink`. This is to avoid creating some non-standard, one-off utility or a service.\r\n\r\n**Expected behavior**\r\n\r\n\u003c!-- Describe what the behavior would be without the bug. -->\r\n\r\nA router also takes a `canRender: []` option. If none is provided, it defaults to `always` render, to ensure backward compatibility.\r\n\r\n``` typescript\r\n// app-routing.module.ts\r\nimport { Routes } from '@angular/router';\r\nconst routes: Routes = [\r\n {\r\n path: '',\r\n component: HomeComponent,\r\n },\r\n {\r\n path: 'account/profile',\r\n component: AccountComponent,\r\n canActivate: [AuthGuardService],\r\n },\r\n {\r\n path: 'account/profile/employee',\r\n component: EmployeeAccountComponent,\r\n canActivate: [AuthGuardService],\r\n canRender: [SupervisorRenderService],\r\n },\r\n {\r\n path: 'login',\r\n component: LoginComponent,\r\n canRender: [UnauthenticatedRenderService],\r\n },\r\n {\r\n path: 'logout',\r\n component: LogoutComponent,\r\n canRender: [AuthenticatedRenderService],\r\n },\r\n {\r\n path: '**',\r\n component: NotfoundComponent,\r\n }\r\n];\r\n```\r\n\r\n**Minimal reproduction of the problem with instructions**\r\nExample for CanRender for `AuthenticatedRenderService`.\r\n\r\n``` typescript\r\n//app/auth/render-guard-service\r\nimport { Injectable } from '@angular/core';\r\nimport { CanRender, Router } from '@angular/router';\r\nimport { AuthService } from './auth.service';\r\n\r\n@Injectable()\r\nexport class AuthenticatedRenderService implements CanRender {\r\n\r\n constructor(private router: Router,\r\n private authService: AuthService) {\r\n }\r\n\r\n CanRender(options: any): boolean {\r\n //...\r\n return this.authService.isAuthenticated;\r\n }\r\n}\r\n```\r\n\r\n``` html\r\n\u003c!-- app/login/login.component.html -->\r\n\u003ca class=\"\" [routerLink]=\"[/login]\">Login\u003c/a> \u003c!-- Render if unauthenticated -->\r\n\u003ca class=\"\" [routerLink]=\"[/logout]\">Logout\u003c/a> \u003c!-- Render if authenticated -->\r\n\u003c!-- all logic in one place, less logic in tempate, cleaner template -->\r\n```\r\n\r\n**What is the motivation / use case for changing the behavior?**\r\n\r\n\u003c!-- Describe the motivation or the concrete use case -->\r\n\r\nIt would be great to put all the route validation/information/title/data in one place. Not showing a sensitive link `sometimes` may be as important as guarding it. (security via obscurity). It also can help with allowing most of the logic to live in one place. This may result in less code as well as helping with DRY. \r\n\r\n**Please tell us about your environment:**\r\n\r\n\u003c!-- Operating system, IDE, package manager, HTTP server, ... -->\r\n\r\nmacOS Sierra, Node v6.6.0, Angular-CLI beta.18, @Angular=2.1.0, @Router=3.1.0","author":{"url":"https://github.com/un33k","@type":"Person","name":"un33k"},"datePublished":"2016-10-24T21:12:25Z","url":"https://github.com/angular/angular/issues/12499"}
| 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:57e4a892-a659-7d55-3d82-422f01f3f478 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8AC2:19AA62:991EA3:C43812:6B00EFB4 |
| html-safe-nonce | a4491433557db51681128c58905980c25566cb80cf79c0d70946e73b1b77dcdf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QUMyOjE5QUE2Mjo5OTFFQTM6QzQzODEyOjZCMDBFRkI0IiwidmlzaXRvcl9pZCI6IjQwODQ0MzUyODA5MTQ4NzAxOTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 61ccb7c0c7b3bcf8e9536f262a45c801aa0048eb8dec9488e603aa41859788c4 |
| hovercard-subject-tag | issue:184956125 |
| 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/12499/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c3e36852e31e8679e182a87af43e4e60ec167f4e58849b35e76d20076bf86973/angular/angular/issues/12499 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c3e36852e31e8679e182a87af43e4e60ec167f4e58849b35e76d20076bf86973/angular/angular/issues/12499 |
| og:image:alt | I'm submitting a ... [ ] 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 h... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | un33k |
| 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