I just recently started using angular 4 instead of angular.js 1.
I have followed the heroes tutorial to learn about the fundamentals of angular 4 and I am currently
This should work
import { Router } from "@angular/router"
export class YourClass{
constructor(private router: Router) { }
YourFunction() {
this.router.navigate(['/path']);
}
}
First you need to import the angular router :
import {Router} from "@angular/router"
Then inject it in your component constructor :
constructor(private router: Router) { }
And finally call the .navigate
method anywhere you need to "redirect" :
this.router.navigate(['/your-path'])
You can also put some parameters on your route, like user/5
:
this.router.navigate(['/user', 5])
Documentation: Angular official documentaiton