首页 > 解决方案 > 角度 6 中的“路由器”类型上不存在属性“getCurrentNavigation”

问题描述

检索状态值:

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”类型中不存在“状态”

标签: angular6router

解决方案


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


推荐阅读