0 votes
in Angular by

How do you define routes?

1 Answer

0 votes
by
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.

 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 { }
...