IndexRoute and browserHistory are not available in the latest version, and Routes do not accept child Routes with v4. Instead, you can specify Routes inside the component itself
import { Switch, BrowserRouter as Router, Route, Redirect } from 'react-router-dom' render(( <Router> <Switch> <Route exact path='/' component={ Main }/> <Redirect from='*' to='/' /> </Switch> </Router> ), document.getElementById('main'))
Then in the main component
render() { const {match} = this.props; return ( <div> {/* other things*/} <Route exact path="/" component={ Search } /> <Route path={'${match.path}cars/:id'} component={ Cars } /> </div> ) }
Similarly, in car components
You will have
render() { const {match} = this.props; return ( <div> {/* other things*/} <Route path={'${match.path}/vegetables/:id'} component={ Vegetables } /> </div> ) }
source share