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

Uncaught TypeError: Cannot read property 'push' of undefined #3225

Closed
bodokaiser opened this issue Mar 24, 2016 · 7 comments
Closed

Uncaught TypeError: Cannot read property 'push' of undefined #3225

bodokaiser opened this issue Mar 24, 2016 · 7 comments

Comments

@bodokaiser
Copy link

Version

2.0.1

Test Case

https://gist.github.com/bodokaiser/8482e0932fe242967c8f

Steps to reproduce

  1. Clone Gist
  2. mkdir app && mv app-index.js app/index.js
  3. npm install && npm start
  4. Click on links

Expected Behavior

Router should dispatch route when clicking on link.

Actual Behavior

Nothing happens.

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

Here seems to be the problem Link.js:124:

this.context.router.push(_location);
@taion
Copy link
Contributor

taion commented Mar 24, 2016

Thanks for your question!

We want to make sure that the GitHub issue tracker remains the best place to track bug reports and feature requests that affect the development of React Router, and per the issue template, we are not handling support requests here.

If you have a question or otherwise need help, please post on Stack Overflow with the #react-router tag at https://stackoverflow.com/questions/ask?tags=react-router, or drop in on the #react-router room on Reactiflux at https://discord.gg/0ZcbPKXt5bYaNQ46.

@taion taion closed this as completed Mar 24, 2016
@bodokaiser
Copy link
Author

@taion This is a bug report.

@taion
Copy link
Contributor

taion commented Mar 24, 2016

You are using the library incorrectly. Please follow the tutorial, consult the documentation, or reach out on a support channel.

@mdarif
Copy link

mdarif commented Apr 21, 2016

+1

@leecade
Copy link

leecade commented Jun 6, 2016

+1 same problem

@ph3b
Copy link

ph3b commented Jun 12, 2016

@taion is correct. The problem is this: https://gist.github.com/bodokaiser/8482e0932fe242967c8f#file-app-index-js-L45:L47. The Link components are used outside the context of the router and will not be able to access your browserHistory object. The Link component needs to be used in a children component of the Router. You should be able to use Link from your Home, About, Contacts components since they are children components of the Router. If you need to handle route changes outside the scope of the router you can pass the browserHistory and call browserHistory.push(path). This is best described here: https://github.com/reactjs/react-router-tutorial/tree/master/lessons/12-navigating

@bodokaiser
Copy link
Author

Yes this is the solution - however it is easy to forget or to not see the problem so it is good that this is now some sort of resource to this problem.

@remix-run remix-run deleted a comment from pbhisay Aug 14, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 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

5 participants