【问题标题】:Include "?" and "=" in URL in Angular 2包括 ”?”和 Angular 2 中的 URL 中的“=”
【发布时间】:2017-06-28 00:54:53
【问题描述】:

在 Angular 2 中,如何在 URL 中包含问号和等号?我尝试了以下两种方法:

在html中:

routerLink="./Example?tour=true"

在 TypeScript 中:

this.router.navigate(['/Example?tour=true']);

这两个例子的结果都是:/Example%3Ftour%3Dtrue

如何让我的 URL 以我想要的方式工作和显示?

【问题讨论】:

标签: angular angular2-routing


【解决方案1】:

我相信这就是您要寻找的:添加 queryParams 对象。

this.router.navigate(['/Example'], {queryParams:{tour:true}});

编辑:记录在这里:https://angular.io/docs/ts/latest/api/router/index/NavigationExtras-interface.html#!#queryParams-anchor

【讨论】:

  • 是的!这正是我所需要的。
猜你喜欢
  • 2016-12-17
  • 1970-01-01
  • 2012-05-17
  • 1970-01-01
  • 1970-01-01
  • 2016-05-14
  • 2017-12-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多