无法读取null的属性'getHostNode' [英] Cannot read property 'getHostNode' of null
问题描述
我有一个视觉/反应应用程序与反应路由器,我的应用程序中有一个简单的按钮:
I have a horizon/react app with react router and I have a simple button in my app:
<Link className="dark button" to="/">Another Search</Link>
当我点击它时,我得到以下异常:
When I click on it, I get the following exception:
Uncaught TypeError: Cannot read property 'getHostNode' of null
错误来自:
getHostNode: function (internalInstance) {
return internalInstance.getHostNode();
},
我知道为什么会得到这个?
Any idea why am I getting this?
推荐答案
我遇到了类似的问题。事实证明,在我的情况下,是highlighthjs从生成的dom中删除注释。
I was facing a similar issue. It turns out that, in my case, was highlighthjs removing comments from the generated dom.
对于文本,React 15正在使用reactid而不是span标记添加注释,如:
For text, React 15 is adding comment with the reactid instead of a span tag, as in:
<!-- react-text: 248-->
Another Search
<!--/react-test-->
你能尝试这样的事吗?
< Link className =dark buttonto =/>< span> Another Search< / span>< / Link>
这将强制生成的DOM包含具有正确 data-reactid
属性的范围。
This will force the generated DOM to include the span with the proper data-reactid
attribute.
我会向react-router提出一个问题,也许他们可以在内部做到这一点,所以你不必为此烦恼。但由于Link孩子基本上可以做任何事情,因此存在挑战。
I would file an issue with react-router, maybe they can do that internally so you would not have to bother about it. But there are challenges with that as the Link child could be basically anything.
这篇关于无法读取null的属性'getHostNode'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!