Importing and setting up the router module

Now, we can start playing around with all the goodies existing in the router library. First things first, we need to import the RouterModule, we do this in the root module of our application. So, we open a file called app.module.ts and insert the following line at the top of the file:

import { RouterModule } from '@angular/router';

Once we have done so, it's time to add the RouterModule as a dependency of the AppModule class.

RouterModule is a little bit of a different module, though; it needs to be initialized at the same time as it is added as a dependant module. It looks like the following:

@NgModule({
imports: [RouterModule.forRoot(routes, <optional config>)]
})

We can see here that it points to variable routes that we have yet to define.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset