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

Importing RouterModule

We configure the router by importing RouterModule, and there are two ways to do it: RouterModule.forRoot and RouterModule.forChild .

RouterModule.forRoot creates a module that contains all the router directives, the given routes, and the router service itself. And RouterModule.forChild creates a module that contains all the directives and the given routes, but does not include the service.

The router library provides two ways to configure the module because it deals with a shared mutable resource—location. That is why we cannot have more than one router service active—they would clobber each other. Therefore we can use forChild to configure every lazy-loaded child module, and forRoot at the root of the application. forChild can be called multiple times, whereas forRoot can be called only once.

@NgModule({
   imports: [RouterModule.forRoot(ROUTES)]
 })
 class MailModule {}
 
 @NgModule({
   imports: [RouterModule.forChild(ROUTES...
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 £16.99/month. Cancel anytime