In the component rendered by react-router i have another routes. However, from these nested routes always only first route is rendered regardless actual path. I read about update blocking and tried to wrap components into withRouter() but it didnt help.
I read about update blocking and tried to wrap components into withRouter() but it didnt help. Reordering routes gives the same behavior.
App.js
class App extends Component{
render() {
return (
<div>
<Router>
<Switch>
<Route path="/login" component={Login} />
<PrivateRoute path="/" component={Main} />
</Switch>
</Router>
<Modal />
</div>
)
}
}
Main.js
class Main extends Component{
render(){
return (
<div className="full-height flex-container flex-column">
<div style={{display: "flex", flexDirection: "row", height: "100%"}}>
<NavigationBar items={[{name: 'Categories', route: '/'}, {name: 'Products', route: '/products'}]} />
<Content />
</div>
</div>
)
}
}
Content.js and problematic routes itself
class Content extends Component{
render(){
return(
<div style={{ width: "100%"}}>
<Switch>
<Route exact to="/" component={CategoriesPage} />
<Route to="/products" component={ProductsPage} />
</Switch>
</div>
)
}
}
I expect for path "/" - CategoriesPage to be rendered, and for "/products" - ProductsPage, but now CategoriesPage rendered for both "/" and "/products". Thanks in advance. Sample available here: https://codesandbox.io/s/github/nomernabis/login-flow-redux.
<Route component={Content} />
instead of<Content />
and see if it changes anything. Apart from it your code looks fine to me – Shubham Khatrito
, usepath
instead. Does it solve your problem ? – R.Duteil