一级页面 引入
如果没有从后台动态获取到接口,可以声明一个数组,再进行遍历获取
let arr= [
{path:’/’,title:‘首页’, exact:true, component:Index},
{path:’/aaa/’,title:‘技术教程’, exact:false, component:Aaa},
{path:’/bbb/’,title:‘小白练习’, exact:false, component:Bbb}
]
import { BrowserRouter as Router, Route, Link } from 'react-router-dom'
import bbb from './Pages/bbb' //二级页面
<Router>
{arr.map((item,index) => {
return (
<li key= {index}> <Link to= {item.path}>{item.title}</Link> </li>
)
{arr.map((item,index) => {
return (
<Route key={index} path={item.path} exact={item.exact} component={item.component} />
)
})}
</Router>
二级页面 引入三级页面用同样的方法,不过不需要 组件包裹,最外一层已经包裹了。