Easy Way Pass Data To CanActivate Guard Angular 4 For Beginner

Short tutorial how to throw data on the canActivate guard API on angular 4. CanActivate is an interface used to check whether a route can be activated or not. Usually used to protect a web page from unauthorized access. And the data thrown on the canActive API is the roles parameter. Okay, follow this simple tutorial.

Another angular tutorial: Tutorial Call Parent Function From Child In Angular 4

You only need to add a “data” property to the angular route interface 4. Read the official route interface documentation here. Properties “data” is additional data provided to the component via ActivatedRoute. For implementation see the following code snippet.

Then how to use the above “data” properties in canActivate guard service like the following code snippet.

Reference : angular.io

So my short tutorial how to quickly pass parameters on canActivate Interface Angular 4, hopefully useful.

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.