【发布时间】:2017-02-19 03:29:39
【问题描述】:
我有一个 Angular 2 应用程序,我使用路由器在视图之间导航,就像其他人一样。这是我的特定组件路径的样子:
{
path: 'home/view1/:viewID',
component: ViewComponent,
children: [
{ path: 'pane/:paneId/section/:sectionId', component: SectionEditComponent },
{ path: '**', component: ViewEditComponent }
]
},
现在,我在 ViewComponent 上有两个按钮,用于为 section1 和 section2 加载 SectionEditComponent。
路径 1:pane/1/section/1
路径2:pane/1/section/2
ViewComponent 模板:
<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 发生变化。
这是已知的还是预期的行为?有什么我做错了吗?
【问题讨论】: