5 lines
16 KiB
JSON
5 lines
16 KiB
JSON
{
|
|
"id": "api/router/RouterModule",
|
|
"title": "RouterModule",
|
|
"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/RouterModule\", \"name\": \"RouterModule\" } }\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/router_module.ts?message=docs(router)%3A%20describe%20your%20change...#L72-L174\" 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/router_module.ts#L72-L174\" 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=\"routermodule\">RouterModule<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/RouterModule#routermodule\"><i class=\"material-icons\">link</i></a></h1>\n \n <label class=\"api-type-label ngmodule\">ngmodule</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>Adds directives and providers for in-app navigation among views defined in an application.\nUse the Angular <code><a href=\"api/router/Router\" class=\"code-anchor\">Router</a></code> service to declaratively specify application states and manage state\ntransitions.</p>\n\n <p><a href=\"api/router/RouterModule#description\">See more...</a></p>\n </section>\n \n \n \n <section class=\"ngmodule-overview\">\n<code-example language=\"ts\" hidecopy=\"true\">\nclass <a href=\"api/router/RouterModule\" class=\"code-anchor\">RouterModule</a> {\n <a class=\"code-anchor\" href=\"api/router/RouterModule#forRoot\">static <span class=\"member-name\">forRoot</span>(routes: Routes, config?: ExtraOptions): ModuleWithProviders<RouterModule></a>\n <a class=\"code-anchor\" href=\"api/router/RouterModule#forChild\">static <span class=\"member-name\">forChild</span>(routes: Routes): ModuleWithProviders<RouterModule></a>\n}\n</code-example>\n\n \n \n\n</section>\n\n\n \n<section class=\"see-also\">\n <h2 id=\"see-also\">See also<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/RouterModule#see-also\"><i class=\"material-icons\">link</i></a></h2>\n <ul>\n \n <li><p><a href=\"guide/router\">Routing and Navigation guide</a> for an\noverview of how the <code><a href=\"api/router/Router\" class=\"code-anchor\">Router</a></code> service should be used.</p>\n</li>\n </ul>\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/RouterModule#description\"><i class=\"material-icons\">link</i></a></h2>\n <p>You can import this NgModule multiple times, once for each lazy-loaded bundle.\nHowever, only one <code><a href=\"api/router/Router\" class=\"code-anchor\">Router</a></code> service can be active.\nTo ensure this, there are two ways to register routes when importing this module:</p>\n<ul>\n<li>The <code>forRoot()</code> method creates an <code><a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a></code> that contains all the directives, the given\nroutes, and the <code><a href=\"api/router/Router\" class=\"code-anchor\">Router</a></code> service itself.</li>\n<li>The <code>forChild()</code> method creates an <code><a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a></code> that contains all the directives and the given\nroutes, but does not include the <code><a href=\"api/router/Router\" class=\"code-anchor\">Router</a></code> service.</li>\n</ul>\n\n \n</section>\n\n \n\n \n\n<section class=\"static-methods\">\n <h2 id=\"static-methods\">Static methods<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/RouterModule#static-methods\"><i class=\"material-icons\">link</i></a></h2>\n \n <a id=\"forRoot\"></a>\n<table class=\"is-full-width method-table static-method\">\n <thead><tr><th>\n <div class=\"with-github-links\">\n <h3 id=\"forroot\">\n forRoot()\n \n <a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/RouterModule#forroot\"><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/router_module.ts?message=docs(router)%3A%20describe%20your%20change...#L102-L153\" 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/router_module.ts#L102-L153\" 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 <tr>\n <td class=\"short-description\">\n <p>Creates and configures a module with all the router providers and directives.\nOptionally sets up an application listener to perform an initial navigation.</p>\n\n </td>\n </tr>\n \n <tr>\n <td>\n <div class=\"overload-info\">\n \n\n <code-example language=\"ts\" hidecopy=\"true\" class=\"no-box api-heading\"><a href=\"api/upgrade/static\" class=\"code-anchor\">static</a> <span class=\"member-name\">forRoot</span>(routes: Routes, config?: ExtraOptions): ModuleWithProviders<RouterModule></code-example>\n\n \n\n <h6 class=\"no-anchor\" id=\"parameters\">Parameters</h6>\n <table class=\"is-full-width list-table parameters-table static-method-overload-parameters\">\n <tbody>\n \n <tr class=\"static-method-overload-parameter\">\n <td class=\"param-name\">\n <a id=\"\"></a>\n <code>routes</code>\n </td>\n <td class=\"param-type\"><code><a href=\"api/router/Routes\" class=\"code-anchor\">Routes</a></code></td>\n <td class=\"param-description\">\n <p>An array of <code><a href=\"api/router/Route\" class=\"code-anchor\">Route</a></code> objects that define the navigation paths for the application.</p>\n\n </td>\n </tr>\n <tr class=\"static-method-overload-parameter\">\n <td class=\"param-name\">\n <a id=\"\"></a>\n <code>config</code>\n </td>\n <td class=\"param-type\"><code><a href=\"api/router/ExtraOptions\" class=\"code-anchor\">ExtraOptions</a></code></td>\n <td class=\"param-description\">\n <p>An <code><a href=\"api/router/ExtraOptions\" class=\"code-anchor\">ExtraOptions</a></code> configuration object that controls how navigation is performed.</p>\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><a href=\"api/core/ModuleWithProviders\" class=\"code-anchor\">ModuleWithProviders</a><<a href=\"api/router/RouterModule\" class=\"code-anchor\">RouterModule</a>></code>: The new <code><a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a></code>.</p>\n\n \n\n\n \n\n \n</div>\n </td>\n </tr>\n \n\n <tr>\n <td class=\"description\">\n <p>When registering the NgModule at the root, import as follows:</p>\n<code-example>\n@<a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a>({\n imports: [RouterModule.forRoot(<a href=\"api/router/ROUTES\" class=\"code-anchor\">ROUTES</a>)]\n})\nclass MyNgModule {}\n</code-example>\n\n </td>\n </tr>\n\n \n </tbody>\n</table>\n\n \n <a id=\"forChild\"></a>\n<table class=\"is-full-width method-table static-method\">\n <thead><tr><th>\n <div class=\"with-github-links\">\n <h3 id=\"forchild\">\n forChild()\n \n <a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/RouterModule#forchild\"><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/router_module.ts?message=docs(router)%3A%20describe%20your%20change...#L154-L173\" 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/router_module.ts#L154-L173\" 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 <tr>\n <td class=\"short-description\">\n <p>Creates a module with all the router directives and a provider registering routes,\nwithout creating a new Router service.\nWhen registering for submodules and lazy-loaded submodules, create the NgModule as follows:</p>\n\n </td>\n </tr>\n \n <tr>\n <td>\n <div class=\"overload-info\">\n \n\n <code-example language=\"ts\" hidecopy=\"true\" class=\"no-box api-heading\"><a href=\"api/upgrade/static\" class=\"code-anchor\">static</a> <span class=\"member-name\">forChild</span>(routes: Routes): ModuleWithProviders<RouterModule></code-example>\n\n \n\n <h6 class=\"no-anchor\" id=\"parameters-1\">Parameters</h6>\n <table class=\"is-full-width list-table parameters-table static-method-overload-parameters\">\n <tbody>\n \n <tr class=\"static-method-overload-parameter\">\n <td class=\"param-name\">\n <a id=\"\"></a>\n <code>routes</code>\n </td>\n <td class=\"param-type\"><code><a href=\"api/router/Routes\" class=\"code-anchor\">Routes</a></code></td>\n <td class=\"param-description\">\n <p>An array of <code><a href=\"api/router/Route\" class=\"code-anchor\">Route</a></code> objects that define the navigation paths for the submodule.</p>\n\n </td>\n </tr>\n </tbody>\n</table>\n\n \n <h6 class=\"no-anchor\" id=\"returns-1\">Returns</h6>\n <p><code><a href=\"api/core/ModuleWithProviders\" class=\"code-anchor\">ModuleWithProviders</a><<a href=\"api/router/RouterModule\" class=\"code-anchor\">RouterModule</a>></code>: The new NgModule.</p>\n\n \n\n\n \n\n \n</div>\n </td>\n </tr>\n \n\n <tr>\n <td class=\"description\">\n <code-example>\n@<a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a>({\n imports: [RouterModule.forChild(<a href=\"api/router/ROUTES\" class=\"code-anchor\">ROUTES</a>)]\n})\nclass MyNgModule {}\n</code-example>\n\n </td>\n </tr>\n\n \n </tbody>\n</table>\n\n \n</section>\n\n \n\n \n\n\n \n\n\n \n\n \n \n<section class=\"directives\">\n <h2 id=\"directives\">Directives<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/router/RouterModule#directives\"><i class=\"material-icons\">link</i></a></h2>\n <table class=\"is-full-width list-table directive-table\">\n <thead>\n <tr><th>Name</th><th>Description</th></tr>\n </thead>\n <tbody>\n \n <tr>\n <td>\n <a href=\"api/router/RouterLink\">\n <code-example language=\"ts\" hidecopy=\"true\" class=\"no-box\">RouterLink</code-example>\n </a>\n </td>\n <td>\n \n <p>When applied to an element in a template, makes that element a link\nthat initiates navigation to a route. Navigation opens one or more routed components\nin one or more <code><<a href=\"api/router/RouterOutlet\" class=\"code-anchor\">router-outlet</a>></code> locations on the page.</p>\n\n </td>\n </tr>\n \n <tr>\n <td>\n <a href=\"api/router/RouterLinkActive\">\n <code-example language=\"ts\" hidecopy=\"true\" class=\"no-box\">RouterLinkActive</code-example>\n </a>\n </td>\n <td>\n \n <p>Tracks whether the linked route of an element is currently active, and allows you\nto specify one or more CSS classes to add to the element when the linked route\nis active.</p>\n\n </td>\n </tr>\n \n <tr>\n <td>\n <a href=\"api/router/RouterLinkWithHref\">\n <code-example language=\"ts\" hidecopy=\"true\" class=\"no-box\">RouterLinkWithHref</code-example>\n </a>\n </td>\n <td>\n \n <p>Lets you link to specific routes in your app.</p>\n\n </td>\n </tr>\n \n <tr>\n <td>\n <a href=\"api/router/RouterOutlet\">\n <code-example language=\"ts\" hidecopy=\"true\" class=\"no-box\">RouterOutlet</code-example>\n </a>\n </td>\n <td>\n \n <p>Acts as a placeholder that Angular dynamically fills based on the current router state.</p>\n\n </td>\n </tr>\n \n </tbody>\n </table>\n</section>\n\n \n \n\n\n \n\n\n </div>\n</article>\n\n<!-- links to this doc:\n - api/router\n - api/router/Resolve\n - api/router/Router\n - api/router/RouterLink\n - api/router/RouterLinkActive\n - api/router/RouterLinkWithHref\n - api/router/RouterOutlet\n - guide/aot-compiler\n - guide/app-shell\n - guide/cheatsheet\n - guide/creating-libraries\n - guide/frequent-ngmodules\n - guide/lazy-loading-ngmodules\n - guide/module-types\n - guide/ngmodule-faq\n - guide/ngmodules\n - guide/route-animations\n - guide/router\n - guide/router-tutorial\n - guide/router-tutorial-toh\n - guide/singleton-services\n - guide/styleguide\n - guide/testing-components-scenarios\n - guide/upgrade\n - tutorial/toh-pt5\n-->\n<!-- links from this doc:\n - /api\n - api/core/ModuleWithProviders\n - api/core/NgModule\n - api/router\n - api/router/ExtraOptions\n - api/router/ROUTES\n - api/router/Route\n - api/router/Router\n - api/router/RouterLink\n - api/router/RouterLinkActive\n - api/router/RouterLinkWithHref\n - api/router/RouterModule#description\n - api/router/RouterModule#directives\n - api/router/RouterModule#forChild\n - api/router/RouterModule#forRoot\n - api/router/RouterModule#forchild\n - api/router/RouterModule#forroot\n - api/router/RouterModule#routermodule\n - api/router/RouterModule#see-also\n - api/router/RouterModule#static-methods\n - api/router/RouterOutlet\n - api/router/Routes\n - api/upgrade/static\n - guide/router\n - https://github.com/angular/angular/edit/master/packages/router/src/router_module.ts?message=docs(router)%3A%20describe%20your%20change...#L102-L153\n - https://github.com/angular/angular/edit/master/packages/router/src/router_module.ts?message=docs(router)%3A%20describe%20your%20change...#L154-L173\n - https://github.com/angular/angular/edit/master/packages/router/src/router_module.ts?message=docs(router)%3A%20describe%20your%20change...#L72-L174\n - https://github.com/angular/angular/tree/12.0.0-next.7/packages/router/src/router_module.ts#L102-L153\n - https://github.com/angular/angular/tree/12.0.0-next.7/packages/router/src/router_module.ts#L154-L173\n - https://github.com/angular/angular/tree/12.0.0-next.7/packages/router/src/router_module.ts#L72-L174\n-->"
|
|
} |