Thuta Learning
AdvancedWeb Developmentintermediate

Routing Basics

Relax. We'll talk through this in plain words — no textbook voice.

In Angular, RouterModule handles client-side routing for single-page applications. When you scaffold a new app project, you can choose to include routing right away.

typescript
// app-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';

const routes: Routes = [
  { path: '', redirectTo: '/home', pathMatch: 'full' },
  { path: 'home', component: HomeComponent },
  { path: 'about', component: AboutComponent },
  { path: '**', component: PageNotFoundComponent }  // 404 page
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

// app.module.ts
import { AppRoutingModule } from './app-routing.module';

@NgModule({
  imports: [BrowserModule, AppRoutingModule]
})
You should see
(The routing module is configured and navigation works)
Routing Basics | Thuta Learning