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 }
]
}]
}
Why not just have the HomeComponent
be the parent component and SideBarComponent
live inside HomeComponent's template?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With