Reactjs 如何通过React中的链接传递函数?

Reactjs 如何通过React中的链接传递函数?,reactjs,react-router,jsx,Reactjs,React Router,Jsx,我必须通过链接将函数传递到另一个组件 testFavorite=()=>{ console.log("work") } <Link to={{ pathname: '/popular', state:{ testFavorite: this.testFavorite } }}> Popular</Link> 但我有

我必须通过链接将函数传递到另一个组件

    testFavorite=()=>{
        console.log("work")
    }

    <Link 
       to={{
       pathname: '/popular',
         state:{
            testFavorite: this.testFavorite
         }
       }}>
   Popular</Link>
但我有这个错误

history.js:370 Uncaught DomeException:未能对“history”执行“pushState”:无法克隆函数(){console.log(“work”);}

我怎样才能修好它? 多谢各位


当您将状态替换为数据时,可以执行此操作

<Link 
       to={{
       pathname: '/popular',
         data:{
            testFavorite: this.testFavorite
         }
       }}>

同时,,如果你还想将数据作为道具传递,你可以使用状态和数据一起传递。你能添加更多信息来帮助你吗?如果我输入链接状态号或字符串,它就是传递,但当我尝试传递函数时,我出现了一个错误。我想一定有一种特殊的方法或类似的方法来传递函数。你不需要什么样的信息你知道吗?这能回答你的问题吗?我认为这一个会解决你的问题(它会帮助你,谢谢)
<Link 
       to={{
       pathname: '/popular',
         data:{
            testFavorite: this.testFavorite
         }
       }}>
this.props.location.state.testFavorite();