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

withRouter error, if used withOUT router #4292

Closed
ghost opened this issue Dec 19, 2016 · 1 comment
Closed

withRouter error, if used withOUT router #4292

ghost opened this issue Dec 19, 2016 · 1 comment
Labels
Milestone

Comments

@ghost
Copy link

ghost commented Dec 19, 2016

Version

3.0.0

Steps to reproduce

use withRouter without a Router ;) (Rendering stuff in styleguidist)
this.props.router is used only in action handlers

Expected Behavior

The component should at least render.

Actual Behavior

Get an error message:

TypeError: Cannot read property 'params' of undefined

Unfortunately, I am unable to debug in styleguidist quickly, but I think the error is coming from here:
https://github.com/ReactTraining/react-router/blob/6eeb7ad358f987520f5b519e48bdd31f725cbade/modules/withRouter.js#L32

Maybe a quick and dirty fix on Line 31 would be enough:

const router = this.props.router || this.context.router || {}

@timdorr
Copy link
Member

timdorr commented Dec 19, 2016

We should probably just return the wrapped component:

if (!router) return <WrappedComponent {...this.props} /> 

A PR for this would be appreciated!

@timdorr timdorr added the bug label Dec 19, 2016
@timdorr timdorr added this to the v3.0.0 milestone Dec 19, 2016
@ghost ghost mentioned this issue Dec 19, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant