how to reload one component with the same url

Viewed 160

Suppose to have a menu with different menu items. When the user click on menu item is redirect to url when the user click at the same menu item the component must be reload so it loses all variables that user put first.

reloaadURL(URL_DESTINATION){
   router.routeReuseStrategy.shouldReuseRoute = () => false;
        router.onSameUrlNavigation = 'reload';
        router.navigate([URL_DESTINATION], { relativeTo: route });

This is my app-routing

path: environment.URL_STUDENT, canActivate: [AuthGuard], children: [
      {
        path: environment.Url_A, loadChildren: () => ....
      },
      {
        path: environment.URL_B, loadChildren: () => ...
      }]
  },
@NgModule({
  imports: [RouterModule.forRoot(routes)
  ],
  exports: [RouterModule]
})

The problem is when the use click the first time on the same link(A) it works all but when the user click to another link (B) the component A is loaded and not B.Anyone can help me?

1 Answers

Use kipLocationChange: true Navigate to the component that you want to reload without changing url

this.router.navigateByUrl('/YourCurrentComponentRefresh', { skipLocationChange: true }).then(() => {
    this.router.navigate(['/YourCurrentComponent']);
}); 
Related