儿童导航 Angular2

Children Navigation Angular2

各位。 我有 @angular/router 问题。 我有我的应用程序的路由配置。

Router [] = [
   {
      path: 'main',
      component: MainComponent,
      children: [
          {
             path: 'info',
             component: InfoComponent
          }
      ]
   }

我有下一个流程:我进入页面并导航到 MainComponent,它只是从 DB 获取对象。在 MainComponent 内部我使用 this.router.navigate(['info'], {relativeTo: this.route})。 在 InfoComponent 中,我有 componentResolver 依赖于 MainComponent

的父级
export class InfoComponent extends OnInit {

    constructor (@Host() private parent: MainComponent) {}

    ...

    ngOnInit () { `componentResolver is done` }
}

问题是,当我通过 Chrome 导航栏中的后退按钮或单击 Alt+< 返回时,它只显示空视图 (MainComponent)。 我的问题在哪里?为什么会这样?

试试这个路由器配置,而不是自己在 MainComponent 中手动进行导航(所以删除 this.router.navigate(['info'], {relativeTo: this.route}) ):

Router [] = [
   {
      path: 'main',
      component: MainComponent,
      children: [
          { 
            path: '', 
            redirectTo: 'info', 
            pathMatch: 'full' 
          },
          {
             path: 'info',
             component: InfoComponent
          }
      ]
   }