我在RouteConfig中定义了routeParam:
{ path: '/user/:id',name: 'User',component: User }
在我的代码中,我调用路由器的导航方法:
userSelected(userid) { this._router.navigate(['User',{ id: userid }]); }
编译器告诉我以下内容:
Argument of type ‘(string | { id: any; })[]’ is not assignable to parameter of type ‘string.
如何键入参数id,以便编译器将其检测为数字?
解决方法
我会直接使用this._router.navigateByUrl(‘user /’userid);