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

    在route组件内定义一个redirect可以可以确定默认加载的选项
    image.png