Angular2 - router-outlet with login structure

前端 未结 3 2048
青春惊慌失措
青春惊慌失措 2021-02-12 12:22

I\'m building angular2 app and currently I have an home component with navbar, toolbar and router-outlet for the main content. I want to add one extra page for the login mechani

3条回答
  •  遥遥无期
    2021-02-12 12:34

    The key is using child routes

    import { RouterModule, Route } from '@angular/router';
    
    const ROUTES: Route[] = [
      { path: 'home', component: HomeComponent },
      { path: 'notes',
        children: [
          { path: '', component: NotesComponent },
          { path: ':id', component: NoteComponent }
        ]
      },
    ];
    
    @NgModule({
      imports: [
        RouterModule.forRoot(ROUTES)
      ]
    })
    

    see more here the-three-pillars-of-angular-routing

提交回复
热议问题