IndexRoute and browserHistory are not available in the latest version, also Routes do not accept children Routes with v4, Instead, you can specify Routes within 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 the cars component
you will have
render() {
const {match} = this.props;
return (
<div>
{/* other things*/}
<Route path={`${match.path}/vegetables/:id`} component={ Vegetables } />
</div>
)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…