【发布时间】:2019-06-26 02:06:35
【问题描述】:
在我的 POC 中,我显示了两个仪表板实例。我希望孩子出现在组件的相应实例中。
但当前的行为是,即使我在第一个实例中单击按钮,子项也会在第二个实例本身中呈现。
仪表板组件.html
<div class="border">
<p>
dashboard works!
</p>
<button [routerLink]="['child1']">one</button>
<button [routerLink]="['child2']">two</button>
<div class="border m-1">
<router-outlet></router-outlet>
</div>
<p>-----------------------------------------------</p>
</div>
app.component.html
<div class="row">
<app-dashboard></app-dashboard> // instance 1
<app-dashboard></app-dashboard> // instance 2
</div>
app.routing.module.ts
const routes: Routes = [
{ path: 'child1',
component: ChildOneComponent
},
{
path: 'child2',
component: ChildTwoComponent
}
];
child-one.component.html
<p>
child-one works!
</p>
child-two.component.html
<p>
child-two works!
</p>
一旦组件加载,我想在子 1 和子 2 中编写额外的代码。
谁能告诉我哪里出错或采取哪种方法?我已经尝试过使用辅助路由并将 id 分配给路由。但他们没有工作。
我只想创建同一个组件的多个实例并在它们内部启用路由,以便路由的特定组件在各自的实例中呈现。
【问题讨论】:
标签: angular routing angular6 angular-routing router-outlet