属性“ getCurrentNavigation”在角度6中的“路由器”类型上不存在

时间:2019-05-02 11:49:25

标签: angular6 router

恢复状态值

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);

获取以下问题

类型“ Router”上不存在属性“ getCurrentNavigation”,并且对象文字只能指定已知属性,并且类型“ NavigationExtras”中不存在“ state”

1 个答案:

答案 0 :(得分:0)

您需要Angular 7.2及更高版本才能使用router.getCurrentNavigation()方法。