ReactRouter 2.0.1上下文缺少链接
ReactRouter 2.0.1 context missing with links
我正在使用react-router
版本2.0.1
和以下文件:
import React, {Component} from 'react'
import {render} from 'react-dom'
import {Link, Router, Route, browserHistory} from 'react-router'
class Home extends Component {
render() {
return (
<div>
<h1>Home</h1>
</div>
)
}
}
class About extends Component {
render() {
return (
<div>
<h1>About</h1>
</div>
)
}
}
class Contact extends Component {
render() {
return (
<div>
<h1>Contact</h1>
</div>
)
}
}
render(
<section>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
<Link to="/contact">Contact</Link>
<Router history={browserHistory}>
<Route path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/contact" component={Contact} />
</Router>,
</section>,
document.querySelector('main')
)
当我点击其中一个链接时,我会得到:
ReactErrorUtils.js:71 Uncaught TypeError: Cannot read property 'push' of undefined
handleClick @ Link.js:124
ReactErrorUtils.invokeGuardedCallback @ ReactErrorUtils.js:71
executeDispatch @ EventPluginUtils.js:79
executeDispatchesInOrder @ EventPluginUtils.js:102
executeDispatchesAndRelease @ EventPluginHub.js:43
executeDispatchesAndReleaseTopLevel @ EventPluginHub.js:54
forEachAccumulated @ forEachAccumulated.js:23
processEventQueue @ EventPluginHub.js:259
runEventQueueInBatch @ ReactEventEmitterMixin.js:18
handleTopLevel @ ReactEventEmitterMixin.js:34
handleTopLevelWithoutPath @ ReactEventListener.js:93
handleTopLevelImpl @ ReactEventListener.js:73
perform @ Transaction.js:136
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:94
dispatchEvent @ ReactEventListener.js:204
带Link.js:124
:
this.context.router.push(_location);
知道我缺了什么吗?
编辑:要找到完整的示例,您可以克隆此要点
this.context.router.push是失败的函数。
因此,要么没有在上下文对象上设置router属性,要么没有传递上下文。。。。
我看到您将链接组件作为路由器组件的对等(而不是子)。
上下文(https://facebook.github.io/react/docs/context.html)是通过组件树传递的,我猜因为链接在组件树之外,所以它们无法找到合适的上下文。
尝试重写应用程序组件树
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 如何使用jQuery自动打开页面上的所有链接
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- jquery动画可以通过编程链接吗
- 在单击href链接的同时下载文件
- 尽管链接成功并已成功下载,但未找到NPM模块
- 制作一个不带HTML a标记但在动画播放完毕后指向其他页面的超链接
- ReactJS映射:如何仅在url变量不为空时呈现html链接
- 单击页面上的链接后高度发生变化
- 将纯文本URL转换为可单击链接
- python-selenium-点击上升链接
- ReactRouter 2.0.1上下文缺少链接
- 如何在右键单击链接并从上下文菜单访问功能后获取链接的 DOM
- 了解用户是否使用上下文菜单打开链接
- 长时间点击safari iphone上的链接后禁用上下文菜单
- 右击潜水与点击事件不39;t在上下文菜单中显示链接选项
- 如何在自定义上下文菜单中添加复制链接位置
- 已部署的bluemix应用上超链接的上下文根目录
- 如何在移动设备上长按显示文本链接上下文而不是URL
- Chrome上下文菜单生成不正确的链接