provideRouter()
Configures the Angular Router with routes and optional features.
Syntax
provideRouter(routes: Routes, ...features): EnvironmentProviders Parameters
| Name | Type | Required | Description |
|---|---|---|---|
routes | Routes | No | The route configuration array. |
features | RouterFeatures[] | No | Optional features like withComponentInputBinding, withHashLocation. |
Returns
EnvironmentProviders — Providers wiring up the router.
Examples
import { provideRouter, withComponentInputBinding } from '@angular/router';
export const appConfig = {
providers: [
provideRouter(
[
{ path: '', component: HomeComponent },
{ path: 'users/:id', component: UserComponent },
],
withComponentInputBinding(),
),
],
};
Notes
Use within bootstrapApplication's providers. Compose optional features:
withComponentInputBinding binds route params to component inputs,
withPreloading sets a preloading strategy, withInMemoryScrolling restores
scroll position. Replaces RouterModule.forRoot.