简体   繁体   English

无法在“历史记录”上执行“ pushState”:函数addComment()……无法克隆

[英]Failed to execute 'pushState' on 'History': function addComment() … could not be cloned

I've tried to make my first app in React and I think I've made some serious error in the flow of the Application however trying to save it doesn't make it better. 我试图在React中制作我的第一个应用程序,但我认为我在应用程序流程中犯了一些严重的错误,但是尝试保存它并不能使其更好。

I got my App.ksin which I have 我有我的App.ksin

<LatestRecipes latestRecipes={this.state.latestRecipes} allRecipes={this.state.recipes} addComment={this.addComment}/>

Right now AddComment is only: 现在,AddComment仅是:

addComment(key, commentData)
{
    console.log(key);
    console.log(commentData);
}

And in latest Recipe I have: 在最新的食谱中,我有:

<Link to={{pathname: '/recipe/' + recipe.name, state: { recipe: recipe, index: index, addComment: this.props.addComment }}}>{recipe.name}</Link>    

This gives me the error: 这给了我错误:

Failed to execute 'pushState' on 'History': function addComment() ... could not be cloned. 无法在“历史记录”上执行“ pushState”:函数addComment()...无法克隆。

What creates the error is the argument: addComment: this.props.addComment 导致错误的是参数: addComment: this.props.addComment

if I remove it everything works but I need to pass my function thos to my Recipe component. 如果删除它,一切正常,但是我需要将功能传递给我的Recipe组件。 Which is in App.js 在App.js中

<Route path="/recipe/:recipe" component={Recipe}/>

Which I need to pass all three arguments, recipe, index and the function addComment() 我需要传递所有三个参数,配方,索引和函数addComment()

Changing: 更改:

<Route path="/recipe/:recipe" component={Recipe}/>

to: 至:

<Route path="/recipe/:recipe" render={(props) => <Recipe {...props} addComment={this.addComment}/>} />

In my App.js solved it. 在我的App.js中解决了它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ReactJS DataCloneError:无法在“历史”上执行“pushState”:无法克隆 MouseEvent object - ReactJS DataCloneError: Failed to execute 'pushState' on 'History': MouseEvent object could not be cloned 未捕获的 DOMException:无法在“历史”上执行“pushState”:函数 () { [本机代码] } 无法克隆 - Uncaught DOMException: Failed to execute 'pushState' on 'History': function () { [native code] } could not be cloned DataCloneError:无法在“历史”上执行“pushState” - DataCloneError: Failed to execute 'pushState' on 'History' 将 React 应用程序注入 Chrome 扩展程序时,无法在“历史记录”上执行“pushState” - Failed to execute 'pushState' on 'History' while injecting React app into Chrome extension 如何修复未捕获的 DOMException:无法在“历史记录”上执行“pushState” - How to fix Uncaught DOMException: Failed to execute 'pushState' on 'History' 反应:未捕获的 DOMException:无法在“历史”上执行“pushState”:历史 state object 和 URL - react:Uncaught DOMException: Failed to execute 'pushState' on 'History': A history state object with URL 使用 react-router-dom 中的“Link”时,为什么“无法在“历史”上执行“pushState”? - Why `Failed to execute 'pushState' on 'History'` when using `Link` from react-router-dom? 未处理的拒绝(TypeError):history.pushState 不是 function - Unhandled Rejection (TypeError): history.pushState is not a function DOMException:无法在“历史”上执行“replaceState”:历史 state object 与 URL - DOMException: Failed to execute 'replaceState' on 'History': A history state object with URL 未捕获的 SecurityError:无法在“历史记录”上执行“replaceState”:历史记录 state object 和 URL - Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM