为了账号安全,请及时绑定邮箱和手机立即绑定

react-router 不用 Link 怎么跳转路由

react-router 不用 Link 怎么跳转路由

Qyouu 2019-03-02 07:03:10
react-router 不用 Link 怎么跳转路由
查看完整描述

1 回答

?
翻过高山走不出你

TA贡献1875条经验 获得超3个赞

history.pushState的话确实只是在history里面添加一条路由记录,并且改变url,不会刷新页面,所以内容不会变,解决的办法可以用如下代码试试:
class Test {
constructor(props, context){
super(props, context);
this.router = context.router;
}
}
Test.contextTypes = {
router: PropTypes.object.isRequired
};

在你ui组件的onChange事件里面写如下代码:

this.router.push(...)

查看完整回答
反对 回复 2019-03-08
  • 1 回答
  • 0 关注
  • 621 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信