简体   繁体   English

react-router链接未在上下文中接收路由器

[英]react-router link not receiving router in context

I'm using React and react-router to create a single page javascript application. 我正在使用React和react-router创建一个单页javascript应用程序。 Each page is it's own component. 每个页面都是它自己的组件。 On one page I am able to create a Link component successfully and it works as intended. 在一页上,我能够成功创建一个Link组件,它可以按预期工作。 On another page I get the following error: 在另一页上,出现以下错误:

Warning: Failed Context Types: Required context `router` was not specified in `Link`.
Uncaught TypeError: Cannot read property 'makeHref' of undefined

Here is the file where I set up my routes: 这是我设置路线的文件:

http://pastebin.com/WBeN9BZw http://pastebin.com/WBeN9BZw

Here is the component where the link works (in the TeamRow component): 这是链接起作用的组件(在TeamRow组件中):

http://pastebin.com/HjG2d43M http://pastebin.com/HjG2d43M

Here is the component where the link doesn't work (line 31): 这是链接不起作用的组件(第31行):

http://pastebin.com/pWb7j8Mk http://pastebin.com/pWb7j8Mk

I logged the contexts throughout the app to examine them and the only time it isn't an empty object is in the App component. 我在整个应用程序中记录了上下文以进行检查,唯一一次它不是空对象是在App组件中。 What am I doing wrong in the TeamPage component that my Link isn't working? 我在Link不能正常工作的TeamPage组件中怎么办? How come the context is empty in the HomePage component but the Link works? 为什么HomePage组件中的上下文为空,但链接有效?

Try changing your require to 尝试将您的需求更改为

// remove the react-router require
var {Link} = require('react-router');

or 要么

// keep the react-router require    
var Link = ReactRouter.Link;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM