1. // import axios from 'axios'
    2. import React, {
    3. Component
    4. } from 'react'
    5. import {Link,Route,Switch} from 'react-router-dom'
    6. import Home from './components/Home'
    7. import About from './components/About'
    8. import Login from './components/Login'
    9. import "./index.css"
    10. class App extends Component {
    11. render() {
    12. return (
    13. <div>
    14. <div className="box">
    15. <div className="box_list">
    16. <div>
    17. <Link to="/home"> 主页</Link>
    18. </div>
    19. <div>
    20. <Link to="/about">关于</Link>
    21. </div>
    22. </div>
    23. <div className="box_content">
    24. <Switch>
    25. <Route path="/home" component={Home}/>
    26. <Route path="/about" component={About}/>
    27. <Route path="/about" component={Login}/>
    28. </Switch>
    29. </div>
    30. </div>
    31. </div>
    32. )
    33. }
    34. }
    35. export default App

    用switch包裹路由可以使得同一路径匹配不同的组件时可以只匹配第一个组件