How can I reload the current page on Angular 2?
if iam in page 2 (pagination) and refresh the page it will show page 1(URL pageload) but i want i refresh the page 2 and it will appear in page 2
This should technically be achievable using window.location.reload()
:
HTML:
<button (click)="refresh()">Refresh</button>
TS:
refresh(): void {
window.location.reload();
}
Update:
Here is a basic StackBlitz example showing the refresh in action. Notice the URL on "/hello" path is retained when window.location.reload()
is executed.
reload()
is a standard browser approach to reloading resources from the current URL.
Jan 21, 2018 at 20:27
window.location.reload()
for chrome on Linux, that would be ideal place for getting your answer, and then you may have a check in your code to get the browser version and have a logic around, Cheers!!