question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Force reload/refresh current route with RouteReuseStrategy

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior With route reuse strategy that is supposed to not reuse a route (shouldReuseRoute returns false) a route is reloaded only if navigated URL is different (e.g. route param).

Currently route component is refreshed only when another route link is navigated. It is not clear if it is a bug or a missing feature.

Expected behavior Route component is expected to be refreshed when any route link is navigated, including the current one.

Minimal reproduction of the problem with instructions A plunk shows that route component is refreshed only when another route link is clicked.

What is the motivation / use case for changing the behavior? Restore $route.reload() functionality from Angular 1. Apparently, the only way to achieve it at this moment is to navigate to temporary route and back. See also #9105

  • Angular version: 2.4.2

  • Browser: [all]

  • Language: [all]

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:38 (9 by maintainers)

github_iconTop GitHub Comments

287reactions
mihaicux2commented, Aug 2, 2017

Hi,

If you really need to trick the Router into reloading the component on each routerLink click, you can use the following code in your Component

constructor(private router: Router){
     // override the route reuse strategy
     this.router.routeReuseStrategy.shouldReuseRoute = function(){
        return false;
     }

     this.router.events.subscribe((evt) => {
        if (evt instanceof NavigationEnd) {
           // trick the Router into believing it's last link wasn't previously loaded
           this.router.navigated = false;
           // if you need to scroll back to top, here is the right place
           window.scrollTo(0, 0);
        }
    });

}

Hope this helps

Mihail C.

119reactions
DzmitryShylovichcommented, Jan 7, 2017

why do u want to reload it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to reload the current route with the angular 2 router
If you want to refresh the data, create a service injected into the component and invoke the load function on the service. If...
Read more >
How to reload/refresh the data when navigate to same route in ...
How to reload/refresh the data when navigate to same route in Angular 9. ... use the Router and override the shouldReuseRoute from the...
Read more >
Angular: Refetch data on same URL navigation - Medium
The onSameUrlNavigation property accepts either 'reload' or 'ignore' as values. ... We need to find out if the current route is refreshed.
Read more >
Router - Angular
'reload' : The router reloads the URL. Use to implement a "refresh" feature. Note that this only configures whether the Route reprocesses the...
Read more >
Reloading components when route parameters change in ...
A simple way to reload component data when route params change in ... URL will be updated but Angular won't refresh the component...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found