We can configure the router service by passing the following options to
RouterModule.forRoot
:
The
enableTracing
option makes the router log all its internal events to the consoleThe
useHash
option enables the location strategy that uses the URL fragment instead of the history APIThe
initialNavigation
option disables the initial navigationThe
errorHandler
option provides a custom error handler
Let's look at each of them in detail.
Setting
enableTracing
to true
is a great way to learn how the router works as shown in the following code:
@NgModule({ imports: [RouterModule.forRoot(ROUTES, {enableTracing: true})] }) class MailModule {}
With this option set, the router will log every internal event to the your console. You'll see something like the following code:
Router Event: NavigationStart NavigationStart(id: 1, url: '/inbox') Router Event: RoutesRecognized RoutesRecognized(id: 1, url: '/inbox', urlAfterRedirects...