markdalgleish/redial

Nested routes, prevent data fetching in parent route if nested route within the parent route is hit.

Opened this issue · 0 comments

I'm having an issue with nested data fetching. If a nested route is hit then the hooks in the parent route are also hit. This results in two requests for data when I only care about the nested route making a call for data.

Ive seen this solution to this problem: #16. Although I don't think this solves this problem fully. What about the case where a parent route is hit, then a nested child route is hit (at this point only the child route would make a request for data), but if I ever went back to the parent route again then data would not be fetched as its state is still populated from the first hit.

Is there anyway using react router to determine the route of the current component thats being rendered? In this case it would be the parent route, and compare this against the requested route (the child component). If this was possible I would be able to compare the two routes and only dispatch actions in my redial hooks when the requested route and current route are the same.

Thanks