IndexRoute和browserHistory在最新版本中不可用,并且Routes不接受带有v4的子级Routes,您可以在组件本身中指定Routes
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'))然后在主要部分
render() { const {match} = this.props; return ( <div>{}<Route exact path="/" component={ Search } /><Route path={`${match.path}cars/:id`} component={ Cars } /> </div> )}同样在汽车组件中
您将拥有
render() { const {match} = this.props; return ( <div>{}<Route path={`${match.path}/vegetables/:id`} component={ Vegetables } /> </div> )}


