Adding multiple routes to our application

Now, let's use HomeComponent and AboutComponent and use them in configuring the routes to these pages in AppRoutingModule:

import { NgModule } from '@angular/core';import { Routes, RouterModule } from '@angular/router';import { HomeComponent } from './home/home.component.ts';import { AboutComponent } from './about/about.component.ts';const routes: Routes = [    { path: '', pathMatch: 'full', redirectTo: 'home' },    { path: 'home', component: HomeComponent },    { path: 'about', component: AboutComponent },    { path: '**', component: HomeComponent },];@NgModule({    imports: [RouterModule.forRoot(routes)],    exports: [RouterModule]})export class AppRoutingModule { }

Here, we added four different routes:

  • The ...

Get Angular Projects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.