2017-08-07 118 views
0

所有人。 我有和@ angular/router問題。 我有我的應用程序的路線配置。兒童導航Angular2

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

和我有下一個流程:1進入該網頁,然後導航到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` } 
} 

的問題是,當我在瀏覽器導航欄導航回來後退按鈕,或者點擊Alt + <,它表明我只是空視圖(MainComponent)。 我的問題在哪裏?爲什麼會發生這種情況?

回答

2

試試這個路由器的配置,而不是手動做自己的導航在MainComponent(所以刪除this.router.navigate(['info'], {relativeTo: this.route})):

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

這僅僅是與調用'Router.navigate' – Dummy

+0

我在一個有此配置我的應用程序,我沒有問題,OP導航返回時提到。 –