Liam
Liam

Reputation: 559

react-router link not receiving router in context

I'm using React and react-router to create a single page javascript application. Each page is it's own component. On one page I am able to create a Link component successfully and it works as intended. 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

Here is the component where the link works (in the TeamRow component):

http://pastebin.com/HjG2d43M

Here is the component where the link doesn't work (line 31):

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. What am I doing wrong in the TeamPage component that my Link isn't working? How come the context is empty in the HomePage component but the Link works?

Upvotes: 8

Views: 2388

Answers (1)

BradByte
BradByte

Reputation: 11093

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;

Upvotes: 1

Related Questions