Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for withRouter not working #4994

Closed
pietro909 opened this issue Apr 18, 2017 · 2 comments
Closed

Example for withRouter not working #4994

pietro909 opened this issue Apr 18, 2017 · 2 comments

Comments

@pietro909
Copy link

Version

4.0.0

Test Case

Please find the test here:
https://codepen.io/pietro909/pen/RVWmwZ?editors=0010#0

based on the default one with dependencies updated to 4.0.0 and the code from https://reacttraining.com/react-router/web/api/withRouter

Same bug on SO:
http://stackoverflow.com/questions/43175941/react-router-cannot-read-property-route-of-undefined
http://stackoverflow.com/questions/43350683/react-router-uncaught-typeerror-cannot-read-property-route-of-undefined

Steps to reproduce

  1. open the codepen
  2. open the console
  3. check for the errors

Expected Behavior

No errors?

Actual Behavior

react-router.js:1160 Uncaught TypeError: Cannot read property 'route' of undefined
at Route.computeMatch (react-router.js:1160)
at new Route (react-router.js:1137)
at react-dom.js:4749
at measureLifeCyclePerf (react-dom.js:4529)
at ReactCompositeComponentWrapper._constructComponentWithoutOwner (react-dom.js:4748)
at ReactCompositeComponentWrapper._constructComponent (react-dom.js:4734)
at ReactCompositeComponentWrapper.mountComponent (react-dom.js:4642)
at Object.mountComponent (react-dom.js:11542)
at ReactCompositeComponentWrapper.performInitialMount (react-dom.js:4825)
at ReactCompositeComponentWrapper.mountComponent (react-dom.js:4712)
@pietro909
Copy link
Author

Going through the code I figured it out: the wrapped component has to be hosted in a *Router component (like BrowserRouter or HashRouter).

This version is working https://codepen.io/pietro909/pen/RVWmwZ

I think we should mention it in the docs given the number of people experiencing this issue.

@pshrmn
Copy link
Contributor

pshrmn commented Apr 18, 2017

#4939 addresses this with a more obvious error.

@timdorr timdorr closed this as completed Apr 19, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants