I have an app in reactJs, using redux and router. I am sorry if this question is more about logic than code, but the problem is very narrow.
I have in my app different categories and each category will set the route like this :
/:category1/
/:category1/:item1
/:category1/:item1/:scheduling1
There is over 50 different route and I set them up all in my router.
<PrivateRoute path="/:category1/:item1/:scheduling1" component={SchedulingComponent} />
<PrivateRoute path="/:category1/:item1" component={ItemComponent} />
<PrivateRoute path="/:category1" component={CateogryComponent} />
Now this work great when the user navigate in the app.
The problem I face is when the user reload the browser or access a link directly.
Since all those path are actually ids, If I access for example /:category1/:item1/:scheduling1
I need to dispatch 3 concatenated action in my redux store
selectCategory
selectItem
selectScheduling
The problem is I do not know how to correctly handle it.
I am confused if the best would be in each component's ComponentDidMount to dispatch some call (but it would also happen when the user navigate and those call are not needed)
Or if there is a way on first load to dispatch all the necessary action. Like making a component in <app> that would just read and dispatch the action when it's mounted (so only once)
not needis, when I navigate, the state are already set, so those component do not need to set redux. But when I visit for the first time, they have to do it.