使用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)

相关文章:

  • 2021-08-30
  • 2021-11-13
  • 2022-01-23
  • 2021-06-05
  • 2021-12-12
  • 2021-07-21
  • 2022-01-19
猜你喜欢
  • 2022-12-23
  • 2021-04-04
相关资源
相似解决方案