How to reload a page in angular2

How to reload a page in angular2.
While searching over the network, I received the code "this._router.renavigate()" to reload the page, but it does not seem to work with the latest version of angular2.
Another way is 'window.location.reload()' , but this is not an angular way to do this.

+7
angular angular2-routing
source share
6 answers

If you really want to reload the page, you need to run location.reload () outside the angular zone

 this.zone.runOutsideAngular(() => { location.reload(); }); 

with RC6

Full example

 import { Component, NgZone } from "@angular/core"; @Component({ templateUrl: "template.html" }) export class ReloadComponent{ constructor( private zone: NgZone) { } reloadPage() { // click handler or similar this.zone.runOutsideAngular(() => { location.reload(); }); } } 
+11
source share

For partial, there is a way to write your own function

  public renavigate(): void { let params: Object = {}; Object.assign(params, this.routeParams.params); params['ref'] = (params['ref'] === ref) ? ref + new Date().getTime() : ref; this.router.navigate(['Foo', params]); } 
+2
source share

This works for me:

 method().subscribe( location.reload(); ); 
+1
source share

I had the same problem and it helped me:

 import { Location } from '@angular/common'; constructor(private location: Location) {} ngOnInit() { this.load(); } load() { this.location.reload(); } 
+1
source share

What about Google visibility using

  *ngIf="auth.loggedIn()" 

which makes much better UX

0
source share

location.reload () will reload the page.

-3
source share

All Articles