无法读取 null 的属性“getHostNode" [英] Cannot read property 'getHostNode' of null

查看:35
本文介绍了无法读取 null 的属性“getHostNode"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有反应路由器的地平线/反应应用程序,我的应用程序中有一个简单的按钮:

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 button" to="/"><span>另一个搜索</span></Link>

这将强制生成的 DOM 包含具有正确 data-reactid 属性的 span.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆