A configuration router base on react-router v4
npm install --save react-config-router
import React from 'react'
import ReactDOM from 'react-dom'
import createRouter from 'react-config-router'
const routes = [
{
path: '/user',
component: UserLayout,
routes: [
{path: '/user', redirect: '/user/login', exact: true},
{
path: '/user/login',
component: Login
},
{
path: '/user/:name',
component: User
}
]
},
]
const historyOpts = {
basename: '/react-config-router'
}
ReactDOM.render(createRouter(routes, {historyOpts}), document.getElementById('root'))
import {history} from 'react-config-router'
history.replace('/')
createRouter(routes,options)
- routes 路由配置
- mode 路由类型
hash | history
- routerProps 传入Router中
- switchProps 传入子路由中
- historyOpts 传入 history 中, 更多配置参考 history
- extraProps 其他 props 传入子路由
MIT © zenghongtu