3

In Angular 2, how do I include a question marks and an equal sign in a URL? I've tried the following two ways:

In the html:

routerLink="./Example?tour=true"

and in TypeScript:

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

Both examples result in: /Example%3Ftour%3Dtrue

How do I get my URLs to work and display the way I want?

Bryan
  • 2,951
  • 11
  • 59
  • 101
  • Related: [How to handle query parameters in angular 2](http://stackoverflow.com/questions/34599174/how-to-handle-query-parameters-in-angular-2) – Josh Crozier Feb 09 '17 at 20:52

1 Answers1

5

I believe this is what you're looking for: adding the queryParams object.

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

edit: documented here: https://angular.io/docs/ts/latest/api/router/index/NavigationExtras-interface.html#!#queryParams-anchor

Jim L
  • 2,297
  • 17
  • 20