我有一个 Angular 2 应用程序,并且像其他人一样使用路由器在视图之间导航。以下是我的特定组件的路径:
{
path: 'home/view1/:viewID',
component: ViewComponent,
children: [
{ path: 'pane/:paneId/section/:sectionId', component: SectionEditComponent },
{ path: '**', component: ViewEditComponent }
]
},
现在,我在视图组件上有两个按钮,用于加载第 1 部分和第 2 部分的部分编辑组件。
路径1:窗格/1/部分/1
路径2:窗格/1/部分/2
视图组件模板:
<div class="col-md-8" style="background-color: white; height: 100%">
<button (click)="loadPath(1)">Path1</button>
<button (click)="loadPath(2)">Path2</button>
<router-outlet></router-outlet>
</div>
现在,当我在同一 ViewComponent 内从 Path1->Path2 或 Path2->Path1 导航时,不会调用 ngOnInit(),因此不会加载新路径,即使 url 实际上根据新的部分 ID 发生变化。
这是已知的或预期的行为吗?我做错了什么吗?
注入路由并订阅参数变化
constructor(route:ActivatedRoute) {
route.params.forEach(params => {
myInit(params['paramId']);
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)