* 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: * * ```ts * @NgModule({ * imports: [RouterModule.for
(routes: Routes, config?: ExtraOptions)
| 125 | * |
| 126 | */ |
| 127 | static forRoot(routes: Routes, config?: ExtraOptions): ModuleWithProviders<RouterModule> { |
| 128 | return { |
| 129 | ngModule: RouterModule, |
| 130 | providers: [ |
| 131 | ROUTER_PROVIDERS, |
| 132 | typeof ngDevMode === 'undefined' || ngDevMode |
| 133 | ? config?.enableTracing |
| 134 | ? withDebugTracing().ɵproviders |
| 135 | : [] |
| 136 | : [], |
| 137 | {provide: ROUTES, multi: true, useValue: routes}, |
| 138 | typeof ngDevMode === 'undefined' || ngDevMode |
| 139 | ? { |
| 140 | provide: ROUTER_FORROOT_GUARD, |
| 141 | useFactory: provideForRootGuard, |
| 142 | } |
| 143 | : [], |
| 144 | config?.errorHandler |
| 145 | ? { |
| 146 | provide: NAVIGATION_ERROR_HANDLER, |
| 147 | useValue: config.errorHandler, |
| 148 | } |
| 149 | : [], |
| 150 | {provide: ROUTER_CONFIGURATION, useValue: config ? config : {}}, |
| 151 | config?.useHash ? provideHashLocationStrategy() : providePathLocationStrategy(), |
| 152 | provideRouterScroller(), |
| 153 | config?.preloadingStrategy ? withPreloading(config.preloadingStrategy).ɵproviders : [], |
| 154 | config?.initialNavigation ? provideInitialNavigation(config) : [], |
| 155 | config?.bindToComponentInputs |
| 156 | ? withComponentInputBinding( |
| 157 | typeof config.bindToComponentInputs === 'object' ? config.bindToComponentInputs : {}, |
| 158 | ).ɵproviders |
| 159 | : [], |
| 160 | config?.enableViewTransitions ? withViewTransitions().ɵproviders : [], |
| 161 | provideRouterInitializer(), |
| 162 | ], |
| 163 | }; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Creates a module with all the router directives and a provider registering routes, |