Closed wardbell closed 8 years ago
The following reasonable line from hero-detail.component.ts does not satisfy the typings:
hero-detail.component.ts
// navigate signature: navigate(commands: any[], extras?: NavigationExtras): Promise<boolean>; this.router.navigate(['/heroes'], { queryParameters: { id: heroId, foo: 'foo' } });
The problem is that heroId is a number, not a string. The type of NavigationExtras is
heroId
NavigationExtras
// NavigationExtras interface NavigationExtras { relativeTo?: ActivatedRoute; queryParameters?: Params; fragment?: string; } // shared declare type Params = { [key: string]: string; // <--- Number disallowed. };
Clearly it works in practice for this use case as clicking the back button returns to the Heroes list and the address bar shows:
Heroes
http://localhost:3000/heroes?id=14&foo=foo
Good news! The parameter are Url encoded.
Changing the parameters in the gotoHeroes method to this
gotoHeroes
{ queryParameters: { id: heroId, foo: 'foo bu' } });
produces the expected url
http://localhost:3000/heroes?id=13&foo=foo%20bu
Closed via https://github.com/angular/vladivostok/commit/10a58f0febbbf1cf6024d6a69bcaab7949062dd2
The following reasonable line from
hero-detail.component.ts
does not satisfy the typings:The problem is that
heroId
is a number, not a string. The type ofNavigationExtras
isClearly it works in practice for this use case as clicking the back button returns to the
Heroes
list and the address bar shows:Bonus: escaped params
Good news! The parameter are Url encoded.
Changing the parameters in the
gotoHeroes
method to thisproduces the expected url