wtorek, 27 lutego 2018

How to reload current page by clicking link again in Angular

In .component.ts file add to constructor:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    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);
      }
    });

Router and NavigationEnd must be imported:


1
import { Router, NavigationEnd } from '@angular/router';


source: https://github.com/angular/angular/issues/13831

Brak komentarzy:

Prześlij komentarz