Importing and configuring the router
In order to define and implement the navigation strategy, we will make use of router and RouterModule
.
We need to update our app.module.ts
file to do the following:
- Import
RouterModule
and routes from Angular router module - Import the application components
- Define the routes with path and component details
- Import
RouterModule.forRoot
(appRoutes
)
Each route definition can have the following keys:
path
: The URL we want to display in the browser address bar.component
: Corresponding component that will hold the view and application logic.redirectTo
(optional): This indicates the URL we want the user to get redirected from this path.pathMatch
(optional): A redirect route requirespathMatch
--it tells the router how to match a URL to the path of a route.pathMatch
can take either value asfull
orprefix
.
We will now import and configure the router in our NgModule
. Take a look at the updated app.module.ts
file with complete implementation of the router:
import { NgModule...