Ravi Sevta
Ravi Sevta

Reputation: 3085

how to reload/refresh previous url in angular 2+?

In my scenario of current Angular 7 application, I'm navigation user to connection lost component if the network stopped. And I'm doing this with skipLocationChange:true flag, like below

this.router.navigate(['/connection-lost'], {skipLocationChange: true});

Now if the network start working. I want to reload the previous page by clicking on the reload button from ConnectionLostComponent.

I tried it by router.navigate([router.url]), but router.url giving the URL /connection-lost not which is showing in address bar

For example, if the user is on the address page('/addresses'), and connection lost. then the user is navigated to ConnectionLostComponent on the same URL('/addresses'). Now if the user click on the reload button, then it should load address page

How can I do it?

Upvotes: 0

Views: 1076

Answers (1)

Ravi Sevta
Ravi Sevta

Reputation: 3085

One solution that I found is to use navigateByUrl method of the Router.

like :

this.router.navigateByUrl(this.location.path(true));

here location from ('@angular/common') gives the exact path which is showing in the address bar.

Upvotes: 0

Related Questions