简体   繁体   English

使用Angular 2 RC6路由器更改URL

[英]Change URL with Angular 2 RC6 Router

I am building a list app, where list-items can be selected. 我正在构建一个列表应用程序,可以在其中选择列表项。 Only one item can be selected at a time. 一次只能选择一项。 A detail-view for the list-item is displayed below the list. 列表项的详细视图显示在列表下方。

Now I want to change the url based on which item is selected, without navigating to another page. 现在,我想基于选择的项目来更改url,而无需导航到另一个页面。

Is it possible? 可能吗? If yes, how? 如果是,怎么办?

Thanks 谢谢

Use route parameters for this 为此使用路线参数

{ 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']);
  }
}

With a router navigation, when only route params change, nothing is reloaded. 使用路由器导航时,仅更改路由参数时,不会重新加载任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM