Web Developer

Section 11 Router & Routing

Set up route:

  • const routes: Routes = [
    • {path: ”, component: HomeComponent}, //localhost:4200/
    • {path: ‘aaa’, component: AaaComponent, //localhost:4200/aaa
      • children: [
        • {path: ‘:id’, component: AaaSubComponent} //localhost:4200/aaa/abc(id is value)
      • ]} ,
    • {path: ‘**’, redirectTo: ‘/’}
  • ]

import: RouterModule to app.module.ts file’s @NgModule({imports: [RouterModule.forRoot(routes)]})

You also can set up routing.module.ts file and then import to app.module.ts file

Leave a Reply

Your email address will not be published. Required fields are marked *.

*
*
You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>