'location' prop not changing in a component with 'withRouter'
See original GitHub issueVersion
4.1.2
Test Case
https://codesandbox.io/s/61m9v82r7n
Steps to reproduce
Navigate between Home and Home + query.
Fix
The problem can be fixed by changing Child from being a PureComponent to Component. This is very weird as it has absolutely no connection to either being a child of the <Route /> component, or being the one that is decorated with withRouter.
Expected Behavior
I expect DeepChild’s location prop to change whenever the URL changes.
Actual Behavior
DeepChild’s prop is not changing despite it being correctly connected to withRouter.
Note
The setup, together with the connect usage, is exactly how I encountered it in my project. I did not test the issue without using connect.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:5 (2 by maintainers)
Top Results From Across the Web
'location' prop not changing in a component with 'withRouter'
The problem can be fixed by changing Child from being a PureComponent to Component . This is very weird as it has absolutely...
Read more >reactjs - match and location prop not updating after link to
Let's consider a basic Page component, using match.params to link to the next page: import { Link } from 'react-router-dom'; export default ({ ......
Read more >withRouter - React Router: Declarative Routing for React.js
withRouter does not subscribe to location changes like React Redux's connect does for state changes. Instead, re-renders after location changes propagate out ...
Read more >The Hooks of React Router - CSS-Tricks
When using the component syntax, route props ( match , location and history ) are implicitly being passed on to the component. But...
Read more >React router not updating component - Sport Castellano Reports
createElement to render the component passed to the component props. ... Nov 23, 2021 · withRouter is not working after updating react-router-dom to...
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

i think that’s not true. A component should never assume whether its children are components or connected containers:
Wether Component1 or Component2 should ever rerender is of no concern of PureComponent. Redux handles this case correctly: if Component1 is
connected, it rerenders its children whenver the mapped state changes.But if Component1 uses
withRouterhoc, it does not re-render on location changes. I would expectwithRouterto behave similar toconnectin this regard.I did read it, however I thought that wrapping a component in
withRoutergets around any blocked updatesdo I understand correctly that I need to wrap every single pure component in the hierarchy in
withRouteror pass thelocationprop from the upmost parent so the changes propagate?