我在使用 this.router.navigate(['/dashboard']) 时得到 "Property 'router' does not exist on type 'SigninComponent'.";在 angular 4

I'm getting "Property 'router' does not exist on type 'SigninComponent'." while using this.router.navigate(['/dashboard']); in angular 4

我有导入:

import { RouterModule, Routes} from '@angular/router';

然后我在组件内部的函数中使用了下面一行

this.router.navigate(['/dashboard']);

你需要在constructor里面传递如下,

constructor(private router: Router){
}

还要确保您已按如下方式导入 Router

import { Router } from '@angular/router';
/* Missing if you are using 'this.router.navigate' */   

import { Router } from '@angular/router'; 

从 angular 路由器导入 ActivatedRoute 库。

import {ActivatedRoute, Router} from '@angular/router';

使用以下custructor

constructor(private route:ActivatedRoute,private router:Router) { }

并调用导航方法

this.router.navigate(['/page2'])

错误:属性 'route' 在类型 'Component'

上不存在

添加模块: 从“@angular/router”导入{ActivatedRoute}; 从“@angular/router”导入{路由器};

构造函数(私有route:ActivatedRoute,私有router:Router){} 代码实现:

this.memberService.getmember(this.route.snapshot.paramMap
      .get('name')).subscribe(member=>{
       this.member=member 
          })   
  }