/react-config-router

A configuration router base on react-router v4

Primary LanguageJavaScript

react-config-router

A configuration router base on react-router v4

NPM JavaScript Style Guide

Install

npm install --save react-config-router

Usage

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'))

use history anywhere (including with Redux)

import {history} from 'react-config-router'

history.replace('/')

API

createRouter(routes,options)

  • routes 路由配置
  • mode 路由类型 hash | history
  • routerProps 传入Router中
  • switchProps 传入子路由中
  • historyOpts 传入 history 中, 更多配置参考 history
  • extraProps 其他 props 传入子路由

License

MIT © zenghongtu