typescript – 如何在Angular2中键入routeParams?

前端之家收集整理的这篇文章主要介绍了typescript – 如何在Angular2中键入routeParams?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在RouteConfig中定义了routeParam:

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

在我的代码中,我调用路由器的导航方法

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

编译器告诉我以下内容

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

如何键入参数id,以便编译器将其检测为数字?

解决方法

我会直接使用this._router.navigateByUrl(‘user /’userid);

猜你在找的Angularjs相关文章