Tekkaman

导航

 

使用Js控制ReactRouter路由

  首先引入PropTypes:

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

  然后定义context的router属性:

ShoppingCart.contextTypes = {
  router: PropTypes.object
};

  最后,使用代码跳转即可。

this.context.router.history.replace('/login')

   goBack方法可以用于回退到前一页面。

this.context.router.history.goBack()

 

参考:

1、https://facebook.github.io/react/docs/context.html

2、http://blog.csdn.net/u010977147/article/details/53490063(此博文面向的是老版本ReactRouter)

posted on 2017-06-29 22:18  Tekkaman  阅读(1649)  评论(0编辑  收藏  举报