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

Viewed 27692

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']);
4 Answers

Import ActivatedRoute library from angular router.

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

Use following custructor

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

And Call navigate method

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

Error: Property 'route' does not exist on type 'Component'

Add Modules : import{ActivatedRoute} from '@angular/router'; import { Router } from '@angular/router';

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

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