5 lines
70 KiB
JSON
5 lines
70 KiB
JSON
{
|
|
"id": "api/router/CanDeactivate",
|
|
"title": "CanDeactivate",
|
|
"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/CanDeactivate\", \"name\": \"CanDeactivate\" } }\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...#L193-L279\" 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#L193-L279\" 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=\"candeactivate\">CanDeactivate<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/CanDeactivate#candeactivate\"><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 a route can be deactivated.\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 begins 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/CanDeactivate#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/CanDeactivate\" class=\"code-anchor\">CanDeactivate</a><T> {\n <a class=\"code-anchor\" href=\"api/router/CanDeactivate#canDeactivate\"><span class=\"member-name\">canDeactivate</span>(component: T, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState?: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<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/CanDeactivate#description\"><i class=\"material-icons\">link</i></a></h2>\n <p>The following example implements a <code><a href=\"api/router/CanDeactivate\" class=\"code-anchor\">CanDeactivate</a></code> function that checks whether the\ncurrent user has permission to deactivate the requested route.</p>\n<code-example>\nclass UserToken {}\nclass Permissions {\n canDeactivate(user: UserToken, id: string): boolean {\n return true;\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/Injectable\" class=\"code-anchor\">Injectable</a>()\nclass CanDeactivateTeam implements <a href=\"api/router/CanDeactivate\" class=\"code-anchor\">CanDeactivate</a><TeamComponent> {\n constructor(private permissions: Permissions, private currentUser: UserToken) {}\n\n canDeactivate(\n component: TeamComponent,\n currentRoute: <a href=\"api/router/ActivatedRouteSnapshot\" class=\"code-anchor\">ActivatedRouteSnapshot</a>,\n currentState: <a href=\"api/router/RouterStateSnapshot\" class=\"code-anchor\">RouterStateSnapshot</a>,\n nextState: <a href=\"api/router/RouterStateSnapshot\" class=\"code-anchor\">RouterStateSnapshot</a>\n ): Observable<boolean|<a href=\"api/router/UrlTree\" class=\"code-anchor\">UrlTree</a>>|Promise<boolean|<a href=\"api/router/UrlTree\" class=\"code-anchor\">UrlTree</a>>|boolean|<a href=\"api/router/UrlTree\" class=\"code-anchor\">UrlTree</a> {\n return this.permissions.canDeactivate(this.currentUser, route.params.id);\n }\n}\n\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 canDeactivate: [CanDeactivateTeam]\n }\n ])\n ],\n providers: [CanDeactivateTeam, UserToken, Permissions]\n})\nclass AppModule {}\n</code-example>\n<p>You can alternatively provide an in-line function with the <code>canDeactivate</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 canDeactivate: ['canDeactivateTeam']\n }\n ])\n ],\n providers: [\n {\n provide: 'canDeactivateTeam',\n useValue: (component: TeamComponent, currentRoute: <a href=\"api/router/ActivatedRouteSnapshot\" class=\"code-anchor\">ActivatedRouteSnapshot</a>, currentState:\n<a href=\"api/router/RouterStateSnapshot\" class=\"code-anchor\">RouterStateSnapshot</a>, nextState: <a href=\"api/router/RouterStateSnapshot\" class=\"code-anchor\">RouterStateSnapshot</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/CanDeactivate#methods\"><i class=\"material-icons\">link</i></a></h2>\n \n <a id=\"canDeactivate\"></a>\n<table class=\"is-full-width method-table instance-method\">\n <thead><tr><th>\n <div class=\"with-github-links\">\n <h3 id=\"candeactivate-1\">\n canDeactivate()\n \n <a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/CanDeactivate#candeactivate-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...#L275-L278\" 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#L275-L278\" 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\">canDeactivate</span>(component: T, currentRoute: <a href=\"api/router/ActivatedRouteSnapshot\" class=\"code-anchor\">ActivatedRouteSnapshot</a>, currentState: <a href=\"api/router/RouterStateSnapshot\" class=\"code-anchor\">RouterStateSnapshot</a>, nextState?: <a href=\"api/router/RouterStateSnapshot\" class=\"code-anchor\">RouterStateSnapshot</a>): Observable<boolean | <a href=\"api/router/UrlTree\" class=\"code-anchor\">UrlTree</a>> | Promise<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>component</code>\n </td>\n <td class=\"param-type\"><code>T</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>currentRoute</code>\n </td>\n <td class=\"param-type\"><code><a href=\"api/router/ActivatedRouteSnapshot\" class=\"code-anchor\">ActivatedRouteSnapshot</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>currentState</code>\n </td>\n <td class=\"param-type\"><code><a href=\"api/router/RouterStateSnapshot\" class=\"code-anchor\">RouterStateSnapshot</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>nextState</code>\n </td>\n <td class=\"param-type\"><code><a href=\"api/router/RouterStateSnapshot\" class=\"code-anchor\">RouterStateSnapshot</a></code></td>\n <td class=\"param-description\">\n <p>Optional. Default is <code>undefined</code>.</p>\n \n </td>\n </tr>\n </tbody>\n</table>\n\n \n <h6 class=\"no-anchor\" id=\"returns\">Returns</h6>\n <p><code>Observable<boolean | <a href=\"api/router/UrlTree\" class=\"code-anchor\">UrlTree</a>> | Promise<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/ActivatedRouteSnapshot\n - api/router/CanDeactivate#canDeactivate\n - api/router/CanDeactivate#candeactivate\n - api/router/CanDeactivate#candeactivate-1\n - api/router/CanDeactivate#description\n - api/router/CanDeactivate#methods\n - api/router/Route\n - api/router/RouterStateSnapshot\n - api/router/UrlTree\n - https://github.com/angular/angular/edit/master/packages/router/src/interfaces.ts?message=docs(router)%3A%20describe%20your%20change...#L193-L279\n - https://github.com/angular/angular/edit/master/packages/router/src/interfaces.ts?message=docs(router)%3A%20describe%20your%20change...#L275-L278\n - https://github.com/angular/angular/tree/12.0.0-next.7/packages/router/src/interfaces.ts#L193-L279\n - https://github.com/angular/angular/tree/12.0.0-next.7/packages/router/src/interfaces.ts#L275-L278\n-->"
|
|
} |