Manual redirect to route in Angular.js

To implement authorisation for you application and for other needs you need to manually redirect to another route. To do this in angular 4 you need to use router package. You can use RouterModule from @angular/router package. First import angular router.

import {Router} from "@angular/router"

Then inject it in your component constructor.

constructor(private router: Router) { }

Now go to any line anywhere you need to redirect the route to and call the ..navigate method.

this.router.navigate(['/your-path'])

You can also set parameters in the navigate method as shown below.

this.router.navigate(['/user',5])