Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to know whether the navigation is cancelled or not?

I am navigating to a route but one of the route guard is returning false in Angular 13.
how to know whether navigation is done or cancelled.
I have done below but then block and finally block consoles are printing even the route guard returns false.

this.router.navigate(['/user/admin/editor'])
      .then(() =>{
        console.log('then block');
        
      })
      .catch(() => {
        console.log('catch block');
        
      })
      .finally(() => {
        console.log('final block');
        
      });

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can subscribe to the router events, more specifically, to the NavigationCancel event:

this.router.events.pipe(
  filter(e => e instanceof NavigationCancel)
).subscribe(() => {
  console.log('navigation was cancelled');
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading