Developing a React application using React router v4. All worked well until I introduced Redux in my app. Since then on click of links to change route the browser url changes but the component corresponding to the route is not getting loaded. It works well if I comment out Redux code. What could be causing this? Here is my code for routing:
import React, { Component } from 'react';
import { Switch, Route, Link } from 'react-router-dom';
import LeftSubDefault from './../components/left-sub-default.component';
import LeftSubOne from './../components/left-sub-one.component';
import LeftSubTwo from './../components/left-sub-two.component';
import { withRouter } from 'react-router-dom';
import { connect } from "react-redux";
import { goToLeftDefault, goToLeftOne, goToLeftTwo } from "./../actions/leftRouteActions.js";
class LeftComponent extends Component {
render() {
return (
<div className="col-xs-6">
<p>
Current sub route: {this.props.currentRoute}
</p>
<ul>
<li onClick={this.props.goToDefault}><Link to={'/'}>Go To Default</Link></li>
<li onClick={this.props.goToSub1}><Link to={'/left-sub1'}>Go To One</Link></li>
<li onClick={this.props.goToSub2}><Link to={'/left-sub2'}>Go To Two</Link></li>
</ul>
<Switch>
<Route exact path='/' component={LeftSubDefault} />
<Route exact path='/left-sub1' component={LeftSubOne} />
<Route exact path='/left-sub2' component={LeftSubTwo} />
</Switch>
</div>
);
}
}
const mapStateToProps = (store) => {
return {
currentRoute: store.routes.currentRoute
};
}
const mapDispatchToProps = (dispatch) => {
return {
goToDefault: () => {
dispatch(goToLeftDefault())
},
goToSub1: () => {
dispatch(goToLeftOne())
},
goToSub2: () => {
dispatch(goToLeftTwo())
}
};
}
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(LeftComponent));
PS: I get no error in console. The code runs clean just components don't load. Here is a similar thread on github: 4671. I have seen lot of threads on various sites but none has the solution for this issue.