This question has already asked.
When we click the second time on a link like that <a routerLink="/home" routerLinkActive="active">Home</a>
, the page does not reload.
Angular2 Router3 - Can't reload/refresh active route
Angular 2 reloads routerLink user clicks again
But it has been solved when angular 2 was in beta version and there was an angular issue regarding the question.
Now that we have angular 4, I will ask if the answers provided are still the best way to solve the issue.
I was curious and did some googling on my own. I found this workaround on a GitHub feature request for Angular:
this._router.routeReuseStrategy.shouldReuseRoute = function(){
return false;
};
this._router.events.subscribe((evt) => {
if (evt instanceof NavigationEnd) {
this._router.navigated = false;
window.scrollTo(0, 0);
}
});
I tried adding this to my app.component.ts ngOnInit
function, and it sure worked. All further clicks on the same link now reloads the component
and data.
Link to original GitHub feature request
Credit goes to mihaicux2 on GitHub.
I tested this on version 4.0.0-rc.3
with import { Router, NavigationEnd } from '@angular/router';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With