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.

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

@ArgOn, Thanks for this response!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.