包括"?" 和Angular 2中的URL中的"="

Bre*_*ett 3 angular2-routing angular

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

在html中:

routerLink="./Example?tour=true"
Run Code Online (Sandbox Code Playgroud)

在TypeScript中:

this.router.navigate(['/Example?tour=true']);
Run Code Online (Sandbox Code Playgroud)

这两个例子都导致: /Example%3Ftour%3Dtrue

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

Jim*_*m L 5

我相信这就是你要找的东西:添加queryParams对象.

this.router.navigate(['/Example'], {queryParams:{tour:true}});
Run Code Online (Sandbox Code Playgroud)

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