2016-09-05 64 views
1

我正在構建一個列表應用程序,其中可以選擇列表項目。 一次只能選擇一個項目。 列表項下方顯示列表項的詳細視圖。使用Angular 2 RC6路由器更改URL

現在我想根據選擇的項目更改網址,而無需導航到其他頁面。

可能嗎?如果是,如何?

感謝

+1

查看我的答案在底部:http://stackoverflow.com/questions/35618463/change-route-params-without-reloading-in-angular-2/39322473#39322473 –

回答

2

使用路由參數此

{ path: '', redirectTo, 'items', pathMatch: 'full' }, 
{ path: 'items', component: ItemList, children: [ 
    { path: '', component: DummyItem }, 
    { path: ':id/detail', component: ItemDetails } 
]} 
<a [routerLink]="itemId + '/detail'">Item {{itemId}}</a> 
class ItemDetail { 
    constructor(route:ActivatedRoute) { 
    route.params.subscribe(params => this.id = params['id']); 
    } 
} 

與路由器導航,當必經之路PARAMS變化,沒有被重新加載。

+1

我已經使用了提供的解決方案下面的答案,因爲它更容易實施我所擁有的。在重構我的代碼的情況下,我將使用您提供的方法。謝謝。 http://stackoverflow.com/questions/35618463/change-route-params-without-reloading-in-angular-2/39322473#39322473 –