1.二级路由
第一种方法
//1.新建两个子路由并在要使用的页面引入 components/Morning Nightimport Morning from './components/Morning'import Night from './components/Night'render() { return ( <div> 关于页面 {/* /about/morning /about/night*/} 使用component这种路由方式,route标签不能有空格 <Route path="/about/morning" component={Morning}></Route> <Route path="/about/night" component={Night}></Route> </div> ); }
第二种方法
<Switch> <Route path="/about/morning"> <Morning></Morning> </Route> <Route path="/about/night"> <Night></Night> </Route> </Switch>
2.路由重定向
// 在import中加入Redirect <Redirect from="/about" to="/about/morning"></Redirect>