My child route components are querying some data from an API. Currently I'm checking in the components if the id supplied as a route param is valid by checking the data the API returned.
I consider this as bad style and want to place the check into a guard that is checking if the supplied params are valid before the component gets activated.
However, I also want to save time and resources. This would require two API requests. Therefore I'm wondering if there is a possibility to pass data from the guard to the component. I thought about passing along with the route params but canActivate
only provides a ActivatedRouteSnapshot
which is read only.
Therefore my question: Is it possible to pass data from a guard to a component? Or is there another (even better) way to save resources and prevent multiple API requests in such cases?