简体   繁体   English

儿童导航Angular2

[英]Children Navigation Angular2

everyone. 大家。 I have and issue with @angular/router. 我有@ angular / router的问题。 I have the routes config for my app. 我有我的应用程序的路由配置。

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

And i have the next flow: i entry the page and it navigates to MainComponent, that just gain the object from DB. 我有下一个流程:我进入页面,然后导航到MainComponent,该组件只是从DB获取对象。 Inside MainComponent i use this.router.navigate(['info'], {relativeTo: this.route}) . 在MainComponent内部,我使用this.router.navigate(['info'], {relativeTo: this.route}) In the InfoComponent i have componentResolver that depends on the parent from the MainComponent 在InfoComponent中,我有componentResolver,它依赖于MainComponent的父级

export class InfoComponent extends OnInit {

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

    ...

    ngOnInit () { `componentResolver is done` }
}

The problem is, when I navigates back by the back button in the Chrome navbar, or clicking Alt+< , it shows me just empty view(MainComponent). 问题是,当我通过Chrome导航栏中的“后退”按钮向后导航,或单击Alt + <时,它只显示了空的view(MainComponent)。 Where is my problem and why is this happened? 我的问题在哪里,为什么会这样?

Try this router configuration instead of doing the navigation yourself manually in the MainComponent (so remove this.router.navigate(['info'], {relativeTo: this.route}) ): 尝试使用此路由器配置,而不要自己在MainComponent中手动进行导航(因此,请删除this.router.navigate(['info'], {relativeTo: this.route}) ):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM