React-router: Warning: Failed context type: The context `router` is marked as required in `Link`, but its value is `undefined`.

Created on 5 Mar 2017  路  10Comments  路  Source: ReactTraining/react-router

I just installed react-route with the following version: "^4.0.0-beta.6" inside a create-react-app application and I can't use <Link>.

I just copy-pasted the basic example in App.js and got the following issue:

Warning: Failed context type: The context `router` is marked as required in `Link`, but its value is `undefined`.

Most helpful comment

Found it -- my bad! I had the component appearing outside the Router component!

All 10 comments

I forced the update to beta.7 and now it works. However, I did not see any mentions of this bug in the CHANGES file...

I have seen a couple people mention this issue. Are you sure that both react-router and react-router-dom were beta 6? I'm guessing that react-router-dom was 6 but react-router was 7.

The context changes are mentioned in this line:

Split context.router into two parts: context.history and context.route

Yes this is possible. I don't know what was the react-router version since I only imported react-router-dom.

The problem is that react-router-dom depends on a version range of react-router. Let me explain; look at the package.json of [email protected]:

https://github.com/ReactTraining/react-router/blob/v4.0.0-beta.5/packages/react-router-dom/package.json#L45

So [email protected] depends on react-router-dom@^4.0.0-beta.5 which will always resolve the latest 4.x. This means that if you use the exact version, it'll break ("react-router-dom": "v4.0.0-beta.5"), and you'll have a version mismatch.

Oh wow... there goes several hours I can't get back. Was having the same issue, didn't realize that my react-router and react-router-dom package versions had drifted. Manually installing both at beta.6 solved the issue.

I'm seeing this error without setting any specific version in my package.json.

I have this in package.json:

    "react-router": "next",
    "react-router-dom": "next",
    "react-router-native": "next",

Which results in the following being installed (according to yarn.lock):

react-router-dom@next:
  version "4.0.0-beta.8"
  resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-4.0.0-beta.8.tgz#907a5a0a36e9190652c80f2feead0eadbbba262e"
  dependencies:
    history "^4.5.1"
    react-router "^4.0.0-beta.8"

react-router-native@next:
  version "4.0.0-beta.8"
  resolved "https://registry.yarnpkg.com/react-router-native/-/react-router-native-4.0.0-beta.8.tgz#cfaab55f8e70cc41e349d1e2f2a2ca3f94b68fc3"
  dependencies:
    react-router "^4.0.0-beta.8"

react-router@^4.0.0-beta.8, react-router@next:
  version "4.0.0-beta.8"
  resolved "https://registry.yarnpkg.com/react-router/-/react-router-4.0.0-beta.8.tgz#368cfe540d23d5d23419b42fb915d465f268b66b"
  dependencies:
    history "^4.6.0"
    invariant "^2.2.2"
    loose-envify "^1.3.1"
    path-to-regexp "^1.5.3"
    warning "^3.0.0"

Install the 4.0.0 final version to be sure!

Also, what kind of project are you working on that needs both react-router-dom and react-router-native? 馃槃

Ok, so now with this in my package.json:

    "react-router": "4.0.0",
    "react-router-dom": "4.0.0",
    "react-router-native": "4.0.0",

I still get the same error.

I'm importing both dom and native because we are using react-native-web to get a web app out of our react native code base.

Found it -- my bad! I had the component appearing outside the Router component!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maier-stefan picture maier-stefan  路  3Comments

alexyaseen picture alexyaseen  路  3Comments

stnwk picture stnwk  路  3Comments

winkler1 picture winkler1  路  3Comments

ArthurRougier picture ArthurRougier  路  3Comments