React Router 4 (beta 8) won't render components if using redux connect
See original GitHub issueVersion
4.0.0-beta.8
If a component containing <Route>
components is exported with a Redux connect wrapper non of the components mapped to those routes components are rendered. Let’s say you have
<BrowserRouter>
<App />
</BrowserRouter>
and App looks like:
class App extends Component {
render() {
return (
<div>
<Route exact path="/" component={Home} />
<Route path="/Test1" component={Test1}/>
<Route path="/Test2" component={Test2} />
</div>
);
}
}
export default connect(mapStateToProps, mapDispatchToProps)(App);
then none of the components get rendered on route changes. If you remove the connect wrapper all works as expected.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:104
- Comments:40 (14 by maintainers)
Top Results From Across the Web
React Router 4 (beta 8) won't render components if using ...
Version 4.0.0-beta.8 If a component containing components is exported with a Redux connect wrapper non of the components mapped to those ...
Read more >reactjs - Router renders nothing - Stack Overflow
I copied store/Router solution from my previous project where it was working fine. Then updated redux/router/dom dependencies, ...
Read more >connected-react-router - npm
A Redux binding for React Router v4 and v5. ... Start using connected-react-router in your project by running `npm i connected-react-router` ...
Read more >React Router DOM: How to handle routing in web apps
React Router DOM contains the DOM bindings for React Router. Learn about its essential components and how to build routes with parameters.
Read more >Suspense for Data Fetching (Experimental) - React
We call this approach “fetch-on-render” because it doesn't start fetching until after the component has rendered on the screen. This leads to a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey klase, I may be mistaken but I think this is exactly the problem I had these previous days. I was used to the v4 alpha API where doing what you shown above worked fine.
In the latest beta API however they kind of went back to their previous way of doing things (that is using react context exclusively to communicate changes), connect() prevents that from working by ways of shouldComponentUpdate.
They have provided again in the beta the withRouter() HOC that solves this nicely, just import it and do
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(App));
This should work just fine after that. Note that you would also need to wrap any redux connected component that has router components inside it with a withRouter(). That means if you have router Links in your redux connected Nav component for example, you would need to wrap it with withRouter() as well.
Hope this helps.
Here is a helpful discussion over on the react-redux repo
This MUST be mentioned very prominently in the docs, it’s an issue many will run into.
I spent a long time scratching my head, trying to figure out why my routes aren’t working.
@timdorr