brandonroberts / vladivostok-sample

1 stars 0 forks source link

Feature: Navigation Extras should accept non-string members #16

Closed wardbell closed 8 years ago

wardbell commented 8 years ago

The following reasonable line from hero-detail.component.ts does not satisfy the typings:

 // 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

// 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:

http://localhost:3000/heroes?id=14&foo=foo

Bonus: escaped params

Good news! The parameter are Url encoded.

Changing the parameters in the gotoHeroes method to this

{ queryParameters: { id: heroId, foo: 'foo bu' } });

produces the expected url

http://localhost:3000/heroes?id=13&foo=foo%20bu
brandonroberts commented 8 years ago

Closed via https://github.com/angular/vladivostok/commit/10a58f0febbbf1cf6024d6a69bcaab7949062dd2