1

我有兩個組成部分component Acomponent BAngular2,如何重新加載組件一次?

在A組份,我發佈一個HTTP請求到服務器,並獲得與狀態=「成功」的響應。在success我與導航狀態=「成功」,以組件B.

在組分B queryParams,我會在構造函數(),如果我得到queryParam's值作爲「成功」,那麼我想只有一次重新加載和重定向檢查到下一個組件C.

我已經使用location.reload()但我最終重新加載組件B一次又一次。

有沒有解決方案?

Component A 
.subscribe(result => { 
    if(result.status == 'success'){ 
     this.router.navigate(['/componentB'],{queryParams:{response: result.status}}); 
             } 

component B constructor(){ 
    this._activatedRoute.queryParams.subscribe(
     (queryParam: any) => this.response = queryParam['response']); 
    if(this.response == 'success'){ 
      this.route.navigate(['/componentC']); 
      window.location.reload(); 
    } 

}

+0

什麼是成分B的功能網址是什麼?你有我們可以看到的任何代碼嗎? –

+0

這是B組件嗎?如果是這樣,你不能直接導航到C,如果「成功」,從我所看到的B是一個不必要的步驟。 –

+0

但由於某種原因,我用來重新加載組件B並獲得result.status形式參數。 – RohanArihant

回答

0

導航到C成分,然後導航至您想要重新加載組件。 //第二個參數_skipLocationChange=true避免後退按鈕

this.route.navigateByUrl('/componentC', true); 
相關問題