2017-10-09 99 views
0

我有下面的代碼角2路線不重裝組件

{ 
    path: 'clientReports', 
    component: ClientsRootComponent, 
    children: [ 
     { 
      path: ':reportId', 
      component: ClientsReportComponent,   
      children: [ 
       { 
        path: ':countryId/:branchId', 
        component: ClientsGridComponent,      
       } 
      ] 
     } 
    ] 
} 

及以下鏈接

app/clientReports/1/1/1 
app/clientReports/2/1/1 
app/clientReports/3/1/1 

每當我點擊一個鏈接,我可以看到ClientsReportComponent不會重新加載,而是存在一個被重用並導致我在該組件的提供程序中聲明的服務生存期問題。

不應該是組件ClientsReportComponent每次點擊一個新的鏈接時重新加載?

回答

1

是的,如果你已經在同一個組件中,它不會重新加載組件。 如果你想在路由上做一些參數改變你已經在的組件,那麼你必須訂閱queryParam/routeparam更改。

請從下面的堆疊鏈路

Router Param Changes

+0

ClientsRootComponent有一些服務注入,我需要銷燬和重用。因此,重用組件對我來說至關重要 – pantonis

+0

在這種情況下,你不能使用EventEmitter並從父組件訂閱? – rijin

+0

有沒有什麼方法可以覆蓋這種行爲? – pantonis