RouterModule
Adds directives and providers for in-app navigation among views defined in an application.
Use the Angular Router
service to declaratively specify application states and manage state
transitions.
forRoot
ModuleWithProviders<RouterModule>
Creates and configures a module with all the router providers and directives. Optionally sets up an application listener to perform an initial navigation.
When registering the NgModule at the root, import as follows:
ExtraOptions | undefined
An ExtraOptions
configuration object that controls how navigation is performed.
ModuleWithProviders<RouterModule>
forChild
ModuleWithProviders<RouterModule>
Creates a module with all the router directives and a provider registering routes, without creating a new Router service. When registering for submodules and lazy-loaded submodules, create the NgModule as follows:
ModuleWithProviders<RouterModule>
Description
Adds directives and providers for in-app navigation among views defined in an application.
Use the Angular Router
service to declaratively specify application states and manage state
transitions.
You can import this NgModule multiple times, once for each lazy-loaded bundle.
However, only one Router
service can be active.
To ensure this, there are two ways to register routes when importing this module: