InterviewHubPRO
Section Overview
Q72

Question 72 of 283

Part 3: Angular Router, Navigation & SSR Universal (63 - 75)

25%
Angular & Signals (283 Qs)•Part 3: Angular Router, Navigation & SSR Universal (63 - 75)

How do you define routes?

A router must be configured with a list of route definitions. You configures the router with routes via the RouterModule.forRoot() method, and adds the result to the AppModule's imports array.

javascript
const appRoutes: Routes = [
{ path: 'todo/:id',      component: TodoDetailComponent },
{
 path: 'todos',
 component: TodosListComponent,
 data: { title: 'Todos List' }
},
{ path: '',
 redirectTo: '/todos',
 pathMatch: 'full'
},
{ path: '**', component: PageNotFoundComponent }
];

@NgModule({
imports: [
 RouterModule.forRoot(
   appRoutes,
   { enableTracing: true } // <-- debugging purposes only
 )
 // other imports here
],
...
})
export class AppModule { }