Skip to content
陈广亮的技术博客
Go back

React Router 4 升级指南

需要的包

"query-string": "5.1.1",
"react-router-dom": "4.3.1",
"connected-react-router": "5.0.1",

关键变更

  1. react-router 4 不再 parse location.search,需要手动用 query-string 解析
  2. 没有 params / routeParams 了,改用 match.params
  3. Route 写法变化:使用 <Route path="/home" render={...} />
  4. history 独立管理import createHistory from 'history/createBrowserHistory'

业务代码迁移

// 之前
import { browserHistory } from "react-router";
browserHistory.push("xxx");

// 之后
import history from "js/redux/middleware/history";
history.push("xxx");

Share this post on:

Previous Post
PWA 入门与实践
Next Post
ES7 Rest/Spread 运算符在对象中的应用