The code below reload a page just once after initial page rendering (loading). It does not reload the page after first reload request was made. I want to know how to reload a page indefinitely. In other words, each time a user make a page reload request then it should happen at all time.
customer.component.ts
constructor(private router: Router ) {
this.router.routeReuseStrategy.shouldReuseRoute = () => {
return false;
};
}
pageReload(){
this.router.navigate(['/customer'], { queryParams: { namevar: this.namevar } });
}
html
<button (click)="pageReload()" > Refresh</button>
2
Try the below code, which reloads the component. The onSameUrlNavigation: 'reload'
and skipLocationChange: true
trigger the component reload without refresh of page.
pageReload() {
this.router.navigateByUrl(`${window.location.pathname}`, {
onSameUrlNavigation: 'reload',
skipLocationChange: true,
});
}
I imported the below line of code into app module and this solved my problem in the above question. The current page is reloading indefinitely.
RouterModule.forRoot(routes, { onSameUrlNavigation: 'reload' })