I am currently developing an application in react using redux, react-router (with pushState History) and react-router-redux. What i am currently doing is that i am binding my routes to specific components, like i saw as best practice in every documentation:
export default function (store) {
return <Route path='/' component={CoreLayout}>
<Route path="feed" components={{content: Feed}} />
<Route path="f/:id" components={{content: FeedItem}} />
</Route>
}
Then i have a Link component like the following somewhere in my Feed component, which is responsible for displaying one specific entry:
<Link to={{ pathname: '/f/' + item.id + '-' + urlSlug(item.title) }}>{item.title}</Link>
The link can then be something like /f/123. So the component FeedItem is loaded when i click on the link navigating to item 123. So far everything is working fine. I also have a specific reducer for my feeditem, connected mapstatetoprops. I think this is all done right.
But my problem or question now is the following:
I have an action called like "SHOW_FEED_ITEM". This action should be used if the user is directly navigating to the the url /f/123, but ideally also if one clicks on the Link component.
But what the router is actually doing is firing a @@router/LOCATION_CHANGE action. From within my reducer, i am able to handle this action and dispatch my own action, but wouldn't prefer this solution since i would have to parse the routing url a second time from there for redirecting into the right action for all those routes.
What i am doing right now is receiving the props.id (coming from the Route f/:id) in my mapStateToProps function and pass it to my component. This is the way my component comes up with the right id.
Now coming to my actual question..
Wouldn't it be better to also tell the Router which Action it should handle instead of just telling him which component(s) it should load?
I know i could add an onClick handler to the Link that dispatches my action but this would only affect a click on the link, no browser back/forth or even refresh user actions.
Is this maybe even already possible right now? How do you guys handle that?