import React from 'react'; import {Switch, Redirect, Route} from 'dva/router'; export default (props)=>{ return <Switch>{ props.routes.map((item, index)=>{ console.log(item.path); return <Route path={item.path} key={index} render={(props)=>{ if (item.children){ return <item.component {...props} routes={item.children}></item.component> }else{ return <item.component {...props}></item.component> } }}></Route> }) }<Redirect from="/" exact to="/tab/index"></Redirect> }</Switch> }2.定义路由列表对象 ————文件名为index.js
import React from 'react'; // 一级路由 import Tab from '../routes/TabPage'; import Detail from '../routes/Detail'; // 二级路由 import Rank from '../routes/RankPage'; import Search from '../routes/SearchPage' import Index from '../routes/IndexPage'; export default { routes: [{ path: '/tab', component: Tab, children: [{ path: '/tab/index', component: Index }, { path: '/tab/rank', component: Rank }, { path: '/tab/search', component: Search }] }, { path: "/detail", component: Detail }] }3.在全局挂载4.在页面中使用
有问题可以留言交流
21 小时前发布
react.js
javascript
36 次阅读 · 读完需要 6 分钟
3
import React from 'react'; import {Switch, Redirect, Route} from 'dva/router'; export default (props)=>{ return <Switch>{ props.routes.map((item, index)=>{ console.log(item.path); return <Route path={item.path} key={index} render={(props)=>{ if (item.children){ return <item.component {...props} routes={item.children}></item.component> }else{ return <item.component {...props}></item.component> } }}></Route> }) }<Redirect from="/" exact to="/tab/index"></Redirect> }</Switch> }2.定义路由列表对象 ————文件名为index.js
import React from 'react'; // 一级路由 import Tab from '../routes/TabPage'; import Detail from '../routes/Detail'; // 二级路由 import Rank from '../routes/RankPage'; import Search from '../routes/SearchPage' import Index from '../routes/IndexPage'; export default { routes: [{ path: '/tab', component: Tab, children: [{ path: '/tab/index', component: Index }, { path: '/tab/rank', component: Rank }, { path: '/tab/search', component: Search }] }, { path: "/detail", component: Detail }] }3.在全局挂载4.在页面中使用
有问题可以留言交流
举报
如果觉得我的文章对你有用,请随意赞赏
评论