【问题标题】:Change URL with Angular 2 RC6 Router使用 Angular 2 RC6 路由器更改 URL
【发布时间】:2017-01-13 06:10:25
【问题描述】:

我正在构建一个列表应用程序,可以在其中选择列表项。 一次只能选择一项。 列表项的详细视图显示在列表下方。

现在我想根据选择的项目更改 url,而不是导航到另一个页面。

有可能吗?如果是,怎么做?

谢谢

【问题讨论】:

标签: angular angular2-routing


【解决方案1】:

为此使用路由参数

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

使用路由器导航,当仅更改路由参数时,不会重新加载任何内容。

【讨论】:

  • 我使用了以下答案中提供的解决方案,因为使用我所拥有的更容易实现。如果要重构我的代码,我将使用您提供的方法。谢谢。 stackoverflow.com/questions/35618463/…
猜你喜欢
  • 2016-09-09
  • 2016-08-31
  • 2018-05-05
  • 1970-01-01
  • 1970-01-01
  • 2020-02-02
  • 2018-09-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多