5 lines
49 KiB
JSON
Raw Permalink Normal View History

{
"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>&#x3C;T> {\n <a class=\"code-anchor\" href=\"api/router/Resolve#resolve\"><span class=\"member-name\">resolve</span>(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable&#x3C;T> | Promise&#x3C;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>&#x3C;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&#x3C;any>|Promise&#x3C;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-a
}