Daniel Hitzel
Daniel Hitzel

Reputation: 1342

How to type routeParams in Angular2?

I have defined routeParam in a RouteConfig:

{ path: '/user/:id', name: 'User', component: User }

In my code I am calling the router's navigation method:

userSelected(userid) {
    this._router.navigate(['User', { id: userid }]);
}

The compiler tells me the following:

Argument of type '(string | { id: any; })[]' is not assignable to parameter of type 'string.

How can I type the parameter id, so the compiler detects it as a number?

Upvotes: 4

Views: 781

Answers (1)

Mohy Eldeen
Mohy Eldeen

Reputation: 1330

I would directly use this._router.navigateByUrl('user/' + userid );

Upvotes: 1

Related Questions