mapToCanActivate converts classes that define canActivate into functional route guards for Angular routing. Apply the result to a route's canActivate property when a class-based guard should control activation. section 26.2.2
A class-based activation guard can:
- Return true to activate a route or false to ignore the navigation request. section 26.2.2
- Return an Observable<boolean> or Promise<boolean> for asynchronous checks; Angular waits for the result. section 26.2.2
- Use dependency injection through a registered guard service while handling application-specific navigation decisions. section 26.2.2
Applying a class guard
Register TermsGuard as a service, import mapToCanActivate and TermsGuard in the routing configuration, then assign canActivate: mapToCanActivate([TermsGuard]) to the protected route. In the example, the guard prompts before opening the product-creation form; Yes resolves true and completes navigation, while No resolves false and cancels it. section 26.2.2
