Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Angular Router

You're reading from   Angular Router From Angular core team member and creator of the router

Arrow left icon
Product type Paperback
Published in Mar 2017
Publisher Packt
ISBN-13 9781787288904
Length 118 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Victor Savkin Victor Savkin
Author Profile Icon Victor Savkin
Victor Savkin
Arrow right icon
View More author details
Toc

Configuring router service

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 console
  • The useHash option enables the location strategy that uses the URL fragment instead of the history API
  • The initialNavigation option disables the initial navigation
  • The errorHandler option provides a custom error handler

Let's look at each of them in detail.

Enable tracing

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime