Angular 2 routing on the same route

I have a Ride component, and a Ride Summary displayed at the end of the trip.

In the right summary there is a button β€œStart a new trip”, which redirects to the same component, Ride .

 [routerLink]="['Ride']" 

Since the Ride component is already the one I'm in, it is not updated and the Ride Summary screen continues to be displayed.

How can I reinitialize the Ride component while re-navigating it? (use ngOnInit method again)

+4
angular
source share
1 answer

Router does not move unless route and params have changed by default.


To do this, you can define

 routerCanReuse(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction){ return false; } 

in your component that you want to edit and call

Router.renavigate();

 this.router.navigate('RouteName', this.routeParams.params) 

recovery.

+4
source share

All Articles