if using redux, the redux connect hoc overrides the shouldcomponentupdate lifecycle method on your component and checks for props and state change this can confuse the react router. something like a user clicking a link will not necessarily change the state or props as is, leading to not re-rendering the components in the routeing context.

the documentation for react router states a solution for this problem:

wrap the component with the withrouter hoc

    import { route, switch, withrouter } from 'react-router-dom';
    import { connect } from 'react-redux';

    const main = (props) => (
        <route exact path='/' component={sample_home}/>
        <route path='/dashboard' component={sample_dashboard}/>    
    export default withrouter(connect()(main))  

also, as an enclosing route component will pass props with a location property, you can pass that into the child component and that should achieve the desired behaviour.


i think the problem here is with redux .. because it blocks rerendering the components as long as the props didn't change,

this is because connect() implements shouldcomponentupdate by default, assuming that your component will produce the same results given the same props and state.

the best solution to this is to make sure that your components are pure and pass any external state to them via props. this will ensure that your views do not re-render unless they actually need to re-render and will greatly speed up your application.

if that’s not practical for whatever reason (for example, if you’re using a library that depends heavily on react context), you may pass the pure: false option to connect():

function mapstatetoprops(state) {
  return { todos: state.todos }

export default connect(mapstatetoprops, null, null, {
  pure: false

here are links for more explanation:

react-redux troubleshooting section

react-router docs

Related Query

More Query from same tag