4

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.

edkeveked
  • 17,989
  • 10
  • 55
  • 93
  • duplicate of: https://stackoverflow.com/questions/40983055/how-to-reload-the-current-route-with-the-angular-2-router – luiscla27 Apr 24 '19 at 20:07

1 Answers1

12

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';

Arg0n
  • 8,283
  • 2
  • 21
  • 38