一、配置二级路由(子路由)
import React, { Component } from 'react';
import Morning from './components/Morning' //引入组件
import Night from './components/Night'
import {
Switch,
Route,
Redirect //路由重定向
} from "react-router-dom"; //引入路由
class About extends Component {
render() {
return (
<div>
关于页面
{/* /about/morning /about/night */}
<div>
<Switch>
<Route path="/about/morning">
<Morning></Morning>
</Route>
<Route path="/about/night">
<Night></Night>
</Route>
<Redirect from="/about" to="/about/morning"></Redirect>
//路由重定向
</Switch>
</div>
</div>
);
}
}
export default About;
//使用component的方法,route标签不能有空格
<Route path="/about/night" component={Night}></Route>