[Fixed] How to control the scope of runGuardsAndResolvers set to always in Angular?

Issue

In our app, I’ve added a resolver that gets the data for a component and I added runGuardsAndResolvers: 'always' so that when, I navigate to the same page that I am on, the resolver will kick in and do its part. That thing works as expected.

Then I added subroutes to that routing config and now, the resolver kicks in on each navigation to deeper level, between children and from child to parent. That made me wonder what scope does that thing have. Evidence shows it spans to all children, grandchildren etc.

Is there any way to keep its scope only to its own level ?

Solution

This answer is w.r.t. Angular v11.x (for future references)…

Yes! Inject the ActivatedRouteSnapshot service and check the route(s). Now you can write your logic here to handle something or return nothing in any of the conditional blocks, e.g. if...else. As per my knowledge, no configuration key is present as of now.

Leave a Reply

(*) Required, Your email will not be published