我有一個路由的Angular 4應用程序。它有這樣的一系列嵌套的路線:如何使用路由來共享Angular 2應用程序的數據?
const routes: Routes = [
{ path: "genes/:id", component: GenePageComponent, children: [
{ path: "mutations/:mutationType", component: MutationPageComponent },
]},
這讓我參觀/genes/123/mutations/non-coding
,這樣的id是123和mutationType是「非編碼」。
如果我注入ActivatedRoute
,我可以訂閱url
或params
,但只爲片段。這意味着我只能在MutationPageComponent
中看到mutationType
。
由於<router-outlet>
無法發出,我怎樣才能將此mutationType
參數與其他更高級別的組件(例如側邊欄,搜索欄或其他頂級組件)共享?
同樣,如何將params.id
從GenePageComponent
傳遞給子代MutationPageComponent
?
您可以從當前的路線得到家長和孩子段參數,可以或者你可以使用一個共享服務,使全球範圍內的可用PARAMS。 –
共享服務可能是我最終要做的。上下走動的孩子看起來就像是脆弱的。 t似乎應該有內置的東西來處理這種情況。 – superluminary