5 lines
49 KiB
JSON

{
"id": "api/router/CanLoad",
"title": "CanLoad",
"contents": "\n\n<article>\n <div class=\"breadcrumb-container\">\n <div class=\"breadcrumb\">\n <script type=\"application/ld+json\">\n {\n \"@context\": \"http://schema.org\",\n \"@type\": \"BreadcrumbList\",\n \"itemListElement\": [\n { \"@type\": \"ListItem\", \"position\": 1, \"item\": { \"@id\": \"https://angular.io//api\", \"name\": \"API\" } },\n { \"@type\": \"ListItem\", \"position\": 2, \"item\": { \"@id\": \"https://angular.io/api/router\", \"name\": \"@angular/router\" } },\n { \"@type\": \"ListItem\", \"position\": 3, \"item\": { \"@id\": \"https://angular.io/api/router/CanLoad\", \"name\": \"CanLoad\" } }\n ]\n }\n </script>\n <a href=\"/api\">API</a> > <a href=\"api/router\">@angular/router</a>\n </div>\n <div class=\"github-links\">\n <a href=\"https://github.com/angular/angular/edit/master/packages/router/src/interfaces.ts?message=docs(router)%3A%20describe%20your%20change...#L390-L472\" aria-label=\"Suggest Edits\" title=\"Suggest Edits\"><i class=\"material-icons\" aria-hidden=\"true\" role=\"img\">mode_edit</i></a>\n <a href=\"https://github.com/angular/angular/tree/12.0.0-next.7/packages/router/src/interfaces.ts#L390-L472\" aria-label=\"View Source\" title=\"View Source\"><i class=\"material-icons\" aria-hidden=\"true\" role=\"img\">code</i></a>\n</div>\n </div>\n \n <header class=\"api-header\">\n <h1 id=\"canload\">CanLoad<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/CanLoad#canload\"><i class=\"material-icons\">link</i></a></h1>\n \n <label class=\"api-type-label interface\">interface</label>\n \n \n \n </header>\n \n <aio-toc class=\"embedded\"></aio-toc>\n\n <div class=\"api-body\">\n \n <section class=\"short-description\">\n <p>Interface that a class can implement to be a guard deciding if children can be loaded.\nIf all guards return <code>true</code>, navigation continues. If any guard returns <code>false</code>,\nnavigation is cancelled. If any guard returns a <code><a href=\"api/router/UrlTree\" class=\"code-anchor\">UrlTree</a></code>, current navigation\nis cancelled and a new navigation starts to the <code><a href=\"api/router/UrlTree\" class=\"code-anchor\">UrlTree</a></code> returned from the guard.</p>\n\n <p><a href=\"api/router/CanLoad#description\">See more...</a></p>\n </section>\n \n \n <section class=\"interface-overview\">\n<code-example language=\"ts\" hidecopy=\"true\">\ninterface <a href=\"api/router/CanLoad\" class=\"code-anchor\">CanLoad</a> {\n <a class=\"code-anchor\" href=\"api/router/CanLoad#canLoad\"><span class=\"member-name\">canLoad</span>(route: Route, segments: UrlSegment[]): Observable&#x3C;boolean | UrlTree> | Promise&#x3C;boolean | UrlTree> | boolean | UrlTree</a>\n}\n</code-example>\n\n \n \n\n\n \n \n\n</section>\n\n \n\n \n \n<section class=\"description\">\n <h2 id=\"description\">Description<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/CanLoad#description\"><i class=\"material-icons\">link</i></a></h2>\n <p>The following example implements a <code><a href=\"api/router/CanLoad\" class=\"code-anchor\">CanLoad</a></code> function that decides whether the\ncurrent user has permission to load requested child routes.</p>\n<code-example>\nclass UserToken {}\nclass Permissions {\n canLoadChildren(user: UserToken, id: string, segments: <a href=\"api/router/UrlSegment\" class=\"code-anchor\">UrlSegment</a>[]): boolean {\n return true;\n }\n}\n\n@<a href=\"api/core/Injectable\" class=\"code-anchor\">Injectable</a>()\nclass CanLoadTeamSection implements <a href=\"api/router/CanLoad\" class=\"code-anchor\">CanLoad</a> {\n constructor(private permissions: Permissions, private currentUser: UserToken) {}\n\n canLoad(route: <a href=\"api/router/Route\" class=\"code-anchor\">Route</a>, segments: <a href=\"api/router/UrlSegment\" class=\"code-anchor\">UrlSegment</a>[]): Observable&#x3C;boolean>|Promise&#x3C;boolean>|boolean {\n return this.permissions.canLoadChildren(this.currentUser, route, segments);\n }\n}\n</code-example>\n<p>Here, the defined guard function is provided as part of the <code><a href=\"api/router/Route\" class=\"code-anchor\">Route</a></code> object\nin the router configuration:</p>\n<code-example>\n@<a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a>({\n imports: [\n RouterModule.forRoot([\n {\n path: 'team/:id',\n component: TeamComponent,\n loadChildren: 'team.js',\n canLoad: [CanLoadTeamSection]\n }\n ])\n ],\n providers: [CanLoadTeamSection, UserToken, Permissions]\n})\nclass AppModule {}\n</code-example>\n<p>You can alternatively provide an in-line function with the <code>canLoad</code> signature:</p>\n<code-example>\n@<a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a>({\n imports: [\n RouterModule.forRoot([\n {\n path: 'team/:id',\n component: TeamComponent,\n loadChildren: 'team.js',\n canLoad: ['canLoadTeamSection']\n }\n ])\n ],\n providers: [\n {\n provide: 'canLoadTeamSection',\n useValue: (route: <a href=\"api/router/Route\" class=\"code-anchor\">Route</a>, segments: <a href=\"api/router/UrlSegment\" class=\"code-anchor\">UrlSegment</a>[]) => true\n }\n ]\n})\nclass AppModule {}\n</code-example>\n\n \n</section>\n\n \n\n \n\n<section class=\"instance-methods\">\n <h2 id=\"methods\">Methods<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/CanLoad#methods\"><i class=\"material-icons\">link</i></a></h2>\n \n <a id=\"canLoad\"></a>\n<table class=\"is-full-width method-table instance-method\">\n <thead><tr><th>\n <div class=\"with-github-links\">\n <h3 id=\"canload-1\">\n canLoad()\n \n <a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/CanLoad#canload-1\"><i class=\"material-icons\">link</i></a></h3>\n <div class=\"github-links\">\n <a href=\"https://github.com/angular/angular/edit/master/packages/router/src/interfaces.ts?message=docs(router)%3A%20describe%20your%20change...#L470-L471\" aria-label=\"Suggest Edits\" title=\"Suggest Edits\"><i class=\"material-icons\" aria-hidden=\"true\" role=\"img\">mode_edit</i></a>\n <a href=\"https://github.com/angular/angular/tree/12.0.0-next.7/packages/router/src/interfaces.ts#L470-L471\" aria-label=\"View Source\" title=\"View Source\"><i class=\"material-icons\" aria-hidden=\"true\" role=\"img\">code</i></a>\n</div>\n </div>\n </th></tr></thead>\n <tbody>\n \n \n <tr>\n <td>\n <div class=\"overload-info\">\n \n\n <code-example language=\"ts\" hidecopy=\"true\" class=\"no-box api-heading\"><span class=\"member-name\">canLoad</span>(route: <a href=\"api/router/Route\" class=\"code-anchor\">Route</a>, segments: <a href=\"api/router/UrlSegment\" class=\"code-anchor\">UrlSegment</a>[]): Observable&#x3C;boolean | <a href=\"api/router/UrlTree\" class=\"code-anchor\">UrlTree</a>> | Promise&#x3C;boolean | <a href=\"api/router/UrlTree\" class=\"code-anchor\">UrlTree</a>> | boolean | <a href=\"api/router/UrlTree\" class=\"code-anchor\">UrlTree</a></code-example>\n\n \n\n <h6 class=\"no-anchor\" id=\"parameters\">Parameters</h6>\n <table class=\"is-full-width list-table parameters-table instance-method-overload-parameters\">\n <tbody>\n \n <tr class=\"instance-method-overload-parameter\">\n <td class=\"param-name\">\n <a id=\"\"></a>\n <code>route</code>\n </td>\n <td class=\"param-type\"><code><a href=\"api/router/Route\" class=\"code-anchor\">Route</a></code></td>\n <td class=\"param-description\">\n \n \n </td>\n </tr>\n <tr class=\"instance-method-overload-parameter\">\n <td class=\"param-name\">\n <a id=\"\"></a>\n <code>segments</code>\n </td>\n <td class=\"param-type\"><code><a href=\"api/router/UrlSegment\" class=\"code-anchor\">UrlSegment</a>[]</code></td>\n <td class=\"param-description\">\n \n \n </td>\n </tr>\n </tbody>\n</table>\n\n \n <h6 class=\"no-anchor\" id=\"returns\">Returns</h6>\n <p><code>Observable&#x3C;boolean | <a href=\"api/router/UrlTree\" class=\"code-anchor\">UrlTree</a>> | Promise&#x3C;boolean | <a href=\"api/router/UrlTree\" class=\"code-anchor\">UrlTree</a>> | boolean | <a href=\"api/router/UrlTree\" class=\"code-anchor\">UrlTree</a></code></p>\n\n \n\n\n \n\n \n</div>\n </td>\n </tr>\n \n\n \n\n \n </tbody>\n</table>\n\n \n</section>\n\n\n \n\n\n </div>\n</article>\n\n<!-- links to this doc:\n - api/router\n - api/router/Route\n - guide/cheatsheet\n - guide/router\n - guide/router-tutorial-toh\n-->\n<!-- links from this doc:\n - /api\n - api/core/Injectable\n - api/core/NgModule\n - api/router\n - api/router/CanLoad#canLoad\n - api/router/CanLoad#canload\n - api/router/CanLoad#canload-1\n - api/router/CanLoad#description\n - api/router/CanLoad#methods\n - api/router/Route\n - api/router/UrlSegment\n - api/router/UrlTree\n - https://github.com/angular/angular/edit/master/packages/router/src/interfaces.ts?message=docs(router)%3A%20describe%20your%20change...#L390-L472\n - https://github.com/angular/angular/edit/master/packages/router/src/interfaces.ts?message=docs(router)%3A%20describe%20your%20change...#L470-L471\n - https://github.com/angular/angular/tree/12.0.0-next.7/packages/router/src/interfaces.ts#L390-L472\n - https://github.com/angular/angular/tree/12.0.0-next.7/packages/router/src/interfaces.ts#L470-L471\n-->"
}