【发布时间】:2020-06-29 17:20:50
【问题描述】:
我必须通过 Link 将函数传递给另一个组件。
testFavorite=()=>{
console.log("work")
}
<Link
to={{
pathname: '/popular',
state:{
testFavorite: this.testFavorite
}
}}>
Popular</Link>
这就是我调用函数的方式
this.props.location.state.testFavorite();
但我有这个错误
history.js:370 未捕获的 DOMException:无法在“历史”上执行“pushState”:function () { console.log("work"); } 无法克隆。
我该如何解决? 非常感谢
【问题讨论】:
-
您能否添加更多信息以帮助您?
-
如果我将 LInk 状态数字或字符串放入它是通过但是当我尝试传递函数时我有一个错误。我认为必须有一个特殊的方法或类似的东西来传递一个函数。什么你想知道什么样的信息?
-
这能回答你的问题吗? stackoverflow.com/questions/52786072/…
-
我觉得这个可以解决你的问题Link
-
有帮助,谢谢)
标签: reactjs react-router jsx