O'Reilly logo

Angular UI Development with PrimeNG by Oleg Varaksin, Sudheer Jonna

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Displaying confirmation dialog with guarded routes

In Angular 2+, you can protect routes with guards. The most likely used guard types are CanActivate and CanDeactivate. The first guard type decides if a route can be activated, and the second one decides if a route can be deactivated. In this section, we will discuss CanDeactivate. This is an interface having only one method canDeactivate:

export interface CanDeactivate<T> {  canDeactivate(component: T, route: ActivatedRouteSnapshot,                     state: RouterStateSnapshot):    Observable<boolean> | Promise<boolean> | boolean;}

This method can return Observable<boolean>, Promise<boolean>, or boolean. If the value of boolean is true, the user can navigate away from the route. If the value of boolean is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required