I have route configuration like this:
[
{
path: '',
component: Home
},
{
path: 'parent',
children: [
{
path: '',
component: ChildComponent1
},
{
path: 'child2',
component: ChildComponent2
},
{
path: 'child3',
component: ChildComponent3
}
]
}
]
I have some HTML (for example toolbar or menu) that i only want to show for components under parent
route i.e. ChildComponent1
, ChildComponent2
, ChildComponent3
, but not for HomeComponent
.
I could include my toolbar in each of those components separately, but that is a lot of repetition if i have large number of those components. Is there a better way?
--------------- EDIT
In Angular 1, using ui-router the solution was pretty straightforward. I would have abstract 'parent' route (state), which in Angular 1 could have its own Controller and Template. Something like this:
{
name: 'parent',
config: {
abstract: true,
url: '/parent-route-url',
title: 'Parent route',
template: '<div class="this-is-my-toolbar"></div><div ui-view></div>'
}
},
// all children of parent will now share common toolbar: <div class="this-is-my-toolbar"></div>
{
name: 'parent.child1',
config: {
url: '',
title: 'Child 1',
template: 'This is child 1',
controller: function() {}
}
},
{
name: 'parent.child2',
config: {
url: 'child2',
title: 'Child 2',
template: 'This is child 2',
controller: function () { }
}
}
In angular 2, abstract route (the one with children) cannot have its own Component with template (or can it?).