有一个基本的DOM:
main
- child A :goBack()
-- subChild A :*
- child B :goBack()
我从app.component.html
向所有DOM子级传播一个footer
元素。
我想知道的是,为什么Back
按钮没有出现在子子级A页面上?
请参见stackblitz。
答案 0 :(得分:1)
您必须将子代创建为实际的子代路线。否则,它将像其他路线一样处理,并完全替换<router-outlet>
标签,在这种情况下为ChildComponent
。
const routes: Routes = [
{ path: '', component: MainComponent },
{
path: ':child', component: ChildComponent, children: [
{ path: 'subChildA', component: SubChildComponent }
]
},
];
此外,您还需要在<router-outlet>
模板中的第二个ChildComponent
标签中,应该在该模板中呈现子路线(子孩子)。
看看修改后的stackblitz。
答案 1 :(得分:0)