属性 'getCurrentNavigation' 在 angular 中的类型 'Router' 上不存在 6

Property 'getCurrentNavigation' does not exist on type 'Router' in angular 6

正在检索状态值:

import { Router,NavigationExtras } from '@angular/router'; 
constructor(private router: Router)
{   
   const navigation = this.router.getCurrentNavigation();
   const state = navigation.extras.state as {example: string};
   this.example = state.example;
}

路线导航

const navigationExtras: NavigationExtras = {state: {example: 'This is an example'}};
  this.router.navigate(['/trace/geospatial'], navigationExtras);

我收到以下错误:

Property 'getCurrentNavigation' does not exist on type 'Router' and Object literal may only specify known properties, and 'state' does not exist in type 'NavigationExtras'

您需要 Angular 7.2 及以上才能使用 router.getCurrentNavigation() 方法。