角路由参数“状态”在类型“ NavigationExtras”中不存在

时间:2019-05-13 13:14:36

标签: angular typescript routing

我想通过这种方式将参数传递给另一个页面:

const navParams:NavigationExtras = {state: {functionalityId:'my id'}};
this.router.navigate(['processes'], navParams);

但是它给了我以下错误:

Type '{ state: { functionalityId: string; }; }' is not assignable to type 'NavigationExtras'.
  Object literal may only specify known properties, and 'state' does not exist in type 'NavigationExtras'.

我也试图直接在导航内传递参数:

this.router.navigate(['processes'], {functionalityId:'my id'});

但我有(几乎)相同的错误:

Argument of type '{ functionalityId: string; }' is not assignable to parameter of type 'NavigationExtras'.
  Object literal may only specify known properties, and 'functionalityId' does not exist in type 'NavigationExtras'

1 个答案:

答案 0 :(得分:-1)

您的语法错误。您需要将方括号放在行尾,如下所示:this.router.navigate(['processes', { functionalityId: 'my id' }])