5 lines
49 KiB
JSON
5 lines
49 KiB
JSON
{
|
|
"id": "api/router/Resolve",
|
|
"title": "Resolve",
|
|
"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/Resolve\", \"name\": \"Resolve\" } }\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...#L285-L389\" 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#L285-L389\" 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=\"resolve\">Resolve<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/Resolve#resolve\"><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 classes can implement to be a data provider.\nA data provider class can be used with the router to resolve data during navigation.\nThe interface defines a <code>resolve()</code> method that is invoked when the navigation starts.\nThe router waits for the data to be resolved before the route is finally activated.</p>\n\n <p><a href=\"api/router/Resolve#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/Resolve\" class=\"code-anchor\">Resolve</a><T> {\n <a class=\"code-anchor\" href=\"api/router/Resolve#resolve\"><span class=\"member-name\">resolve</span>(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<T> | Promise<T> | T</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/Resolve#description\"><i class=\"material-icons\">link</i></a></h2>\n <p>The following example implements a <code>resolve()</code> method that retrieves the data\nneeded to activate the requested route.</p>\n<code-example>\n@<a href=\"api/core/Injectable\" class=\"code-anchor\">Injectable</a>({ providedIn: 'root' })\nexport class HeroResolver implements <a href=\"api/router/Resolve\" class=\"code-anchor\">Resolve</a><Hero> {\n constructor(private service: HeroService) {}\n\n resolve(\n route: <a href=\"api/router/ActivatedRouteSnapshot\" class=\"code-anchor\">ActivatedRouteSnapshot</a>,\n <a href=\"api/animations/state\" class=\"code-anchor\">state</a>: <a href=\"api/router/RouterStateSnapshot\" class=\"code-anchor\">RouterStateSnapshot</a>\n ): Observable<any>|Promise<any>|any {\n return this.service.getHero(route.paramMap.get('id'));\n }\n}\n</code-example>\n<p>Here, the defined <code>resolve()</code> 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: 'detail/:id',\n component: HeroDetailComponent,\n resolve: {\n hero: HeroResolver\n }\n }\n ])\n ],\n exports: [<a href=\"api/router/RouterModule\" class=\"code-anchor\">RouterModule</a>]\n})\nexport class AppRoutingModule {}\n</code-example>\n<p>You can alternatively provide an in-line function with the <code>resolve()</code> signature:</p>\n<code-example>\nexport const myHero: Hero = {\n // ...\n}\n\n@<a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a>({\n imports: [\n RouterModule.forRoot([\n {\n path: 'detail/:id',\n component: HeroComponent,\n resolve: {\n hero: 'heroResolver'\n }\n }\n ])\n ],\n providers: [\n {\n provide: 'heroResolver',\n useValue: (route: <a href=\"api/router/ActivatedRouteSnapshot\" class=\"code-anchor\">ActivatedRouteSnapshot</a>, <a href=\"api/animations/state\" class=\"code-anchor\">state</a>: <a href=\"api/router/RouterStateSnapshot\" class=\"code-anchor\">RouterStateSnapshot</a>) => myHero\n }\n ]\n})\nexport class AppModule {}\n</code-example>\n\n <p>Further information available in the <a href=\"api/router/Resolve#usage-notes\">Usage Notes</a>...</p>\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/Resolve#methods\"><i class=\"material-icons\">link</i></a></h2>\n \n <a id=\"resolve\"></a>\n<table class=\"is-full-width method-table instance-method\">\n <thead><tr><th>\n <div class=\"with-github-links\">\n <h3 id=\"resolve-1\">\n resolve()\n \n <a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/Resolve#resolve-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...#L388-L388\" 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#L388-L388\" 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\">resolve</span>(route: <a href=\"api/router/ActivatedRouteSnapshot\" class=\"code-anchor\">ActivatedRouteSnapshot</a>, <a href=\"api/animations/state\" class=\"code-anchor\">state</a>: <a href=\"api/router/RouterStateSnapshot\" class=\"code-anchor\">RouterStateSnapshot</a>): Observable<T> | Promise<T> | T</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/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><a href=\"api/animations/state\" class=\"code-anchor\">state</a></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 </tbody>\n</table>\n\n \n <h6 class=\"no-anchor\" id=\"returns\">Returns</h6>\n <p><code>Observable<T> | Promise<T> | T</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<section class=\"usage-notes\">\n <h2 id=\"usage-notes\">Usage notes<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/Resolve#usage-notes\"><i class=\"material-icons\">link</i></a></h2>\n <p>When both guard and resolvers are specified, the resolvers are not executed until\nall guards have run and succeeded.\nFor example, consider the following route configuration:</p>\n<code-example>\n{\n path: 'base'\n canActivate: [BaseGuard],\n resolve: {data: BaseDataResolver}\n children: [\n {\n path: 'child',\n guards: [ChildGuard],\n component: ChildComponent,\n resolve: {childData: ChildDataResolver}\n }\n ]\n}\n</code-example>\n<p>The order of execution is: BaseGuard, ChildGuard, BaseDataResolver, ChildDataResolver.</p>\n\n</section>\n\n\n\n </div>\n</article>\n\n<!-- links to this doc:\n - api/common/AsyncPipe\n - api/router\n - api/router/Route\n - guide/cheatsheet\n - guide/glossary\n - guide/lazy-loading-ngmodules\n - guide/router\n - guide/router-tutorial-toh\n-->\n<!-- links from this doc:\n - /api\n - api/animations/state\n - api/core/Injectable\n - api/core/NgModule\n - api/router\n - api/router/ActivatedRouteSnapshot\n - api/router/Resolve#description\n - api/router/Resolve#methods\n - api/router/Resolve#resolve\n - api/router/Resolve#resolve-1\n - api/router/Resolve#usage-notes\n - api/router/Route\n - api/router/RouterModule\n - api/router/RouterStateSnapshot\n - https://github.com/angular/angular/edit/master/packages/router/src/interfaces.ts?message=docs(router)%3A%20describe%20your%20change...#L285-L389\n - https://github.com/angular/angular/edit/master/packages/router/src/interfaces.ts?message=docs(router)%3A%20describe%20your%20change...#L388-L388\n - https://github.com/angular/angular/tree/12.0.0-next.7/packages/router/src/interfaces.ts#L285-L389\n - https://github.com/angular/angular/tree/12.0.0-next.7/packages/router/src/interfaces.ts#L388-L388\n-->"
|
|
} |