1

I am using (angular2) want to hide the side menu on clicking any of its links.

I read this question & its accepted answer referenced in this article.

the solution works good if the user click on [routerLink] other than the currently active one. but ith the current active link is clicked no event emitted.

this is the code:

constructor(
      private router: Router,
      public zone: NgZone) {
      router.events.subscribe( (event: Event) => {

          if (event instanceof NavigationStart) {
              // Show loading indicator
          }

          if (event instanceof NavigationEnd) {
              // Hide loading indicator
              this.w3_close(); // function to hide the menu
          }

          if (event instanceof NavigationError) {
              // Hide loading indicator
              // Present error to user
              console.log(event.error);
          }
      });

}

tabebqena
  • 1,204
  • 1
  • 13
  • 23
  • you could force the navigation to happen even when the route has not changed, which is what happens when a user clicks on an active link. Something similar to ** RouterModule.forRoot(routes, {onSameUrlNavigation: ‘reload’})] ** – Luv Jul 26 '18 at 08:28
  • @Luv ; Your solution works good, but what to do if reloading is expensive??. In all cases I suggest to write your solution as answer. thank you – tabebqena Jul 26 '18 at 09:10

0 Answers0