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

Prateek Jadhav picture Prateek Jadhav · Jul 3, 2017 · Viewed 19.4k times · Source

I have import :

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

and then I have used below line in my function inside component

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

Answer

Sajeetharan picture Sajeetharan · Jul 3, 2017

You need to pass it inside the constructor as follows,

constructor(private router: Router){
}

Also make sure you have imported Router as follows

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