React history.push 传递参数
react 组件之间跳转传递参数,在push的时候设置state 属性,然后再目标组件的props 中能够对传过来的参数进行接收
·
从一个组件跳转到另外的组件,通过代码控制跳转如下:
history.push("/index/goodsinfo/goodsdetail"); ///index/goodsinfo/goodsdetail 是地址
history.go();
这个过程中如何传递参数:
history.push({pathname:'/index/goodsinfo/editgoods/',state:{info:"你好,我是info"}})
history.go();
history.push 可以使用多个参数 state 可以包含我们需要传递的参数
在目标组件中,构造函数里面的props 我们打印出来结果如下:

可以看到的是location 中有state 这个属性,里面就包含我们传过来的参数

希望对你有所帮助!
更多推荐



所有评论(0)