react-router-dom 手动控制路由跳转

基于 react-router 4.0 版本,我们想要通过 JS 手动控制路由跳转,分三步:

第一步:引入 propTypes

const PropTypes = require('prop-types');

第二步:定义context 的router属性

BottomNavigationExampleSimple.contextTypes = {
  router: PropTypes.object
}

第三步:控制跳转

 handleClick= () => {
    this.context.router.history.replace('/index')
  };
posted @ 2017-08-10 17:00  Liaofy  阅读(3996)  评论(0编辑  收藏  举报