一、配置二级路由(子路由)

  1. import React, { Component } from 'react';
  2. import Morning from './components/Morning' //引入组件
  3. import Night from './components/Night'
  4. import {
  5. Switch,
  6. Route,
  7. Redirect //路由重定向
  8. } from "react-router-dom"; //引入路由
  9. class About extends Component {
  10. render() {
  11. return (
  12. <div>
  13. 关于页面
  14. {/* /about/morning /about/night */}
  15. <div>
  16. <Switch>
  17. <Route path="/about/morning">
  18. <Morning></Morning>
  19. </Route>
  20. <Route path="/about/night">
  21. <Night></Night>
  22. </Route>
  23. <Redirect from="/about" to="/about/morning"></Redirect>
  24. //路由重定向
  25. </Switch>
  26. </div>
  27. </div>
  28. );
  29. }
  30. }
  31. export default About;
  1. //使用component的方法,route标签不能有空格
  2. <Route path="/about/night" component={Night}></Route>