Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple components per route in angular

What I want to do is, I want to load the home component and sidebar component at the same time.

const appRoutes: Routes = [
  {
    path: '', component: HomeComponent, children: [{
      path: 'sidebar', component: SidebarComponent, children: [
        { path: 'about', component: AboutComponent },
        { path: 'clients', component: ClientsComponent },
        { path: 'services', component: ServicesComponent },
        { path: 'contact', component: ContactComponent },
        { path: 'datatable', component: DataComponent }
      ]
    }]
  }
like image 914
SONGSTER Avatar asked Jan 13 '18 21:01

SONGSTER


2 Answers

Why not just have the HomeComponent be the parent component and SideBarComponent live inside HomeComponent's template?

like image 23
Mike Tung Avatar answered Nov 16 '22 21:11

Mike Tung


You can use named outlets:

const appRoutes: Routes = [
  {
    path: '', component: HomeComponent, children: [

        { path: 'about', component: AboutComponent },
        { path: 'clients', component: ClientsComponent },
        { path: 'services', component: ServicesComponent },
        { path: 'contact', component: ContactComponent },
        { path: 'datatable', component: DataComponent }
      ]
  },
  { path: '', component: SidebarComponent, outlet:'secondary' }
]

HTML:

<router-outlet></router-outlet> //primary outlet
<router-outlet name="secondary"></router-outlet>  //secondary outlet
like image 187
pixelbits Avatar answered Nov 16 '22 21:11

pixelbits