Step 1: Create two new files in your app folder for basic components which will display the views we would like to route between. I’ve called mine Home and Away.

Step 2: Edit the app.component.html in your app folder to contain the router-outlet.

Step 3: Create an ‘app.routes.ts’ file in your app folder. This example defaults to displaying the HomeComponent and displays the AwayComponent for path “away”.

Step 4: Update the ‘app.module.ts’ file. This is the most complicated step. I’ve shown the before and after files in the screenshot below (click image to enlarge):

Why all the changes to app.module.ts and what do they do?

Lines 5, 29, and 30: In order for us to log the routes to the console on start up which is good for debugging, you need to import the Router module (line 5). This gives us the ability to inject the router object into the constructor (line 29). Line 30 logs the router to the console on app start up.