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

Incompatible with react-router v4.4.0-beta.6 #206

Closed
filoxo opened this issue Dec 13, 2018 · 8 comments
Closed

Incompatible with react-router v4.4.0-beta.6 #206

filoxo opened this issue Dec 13, 2018 · 8 comments

Comments

@filoxo
Copy link

filoxo commented Dec 13, 2018

I was upgrading an older app and attempting to use connected-react-router, and encountered the following error being generated by react-router when attempting to wrap Links and Switches in this library's ConnectedRouter.

Error: Invariant failed: You should not use <Link> outside a <Router>

Repro example: https://codesandbox.io/s/ymk0787ox

I'm not familiar with how react-router previously allowed other Router implementations, but it seems that this future version no longer will. I'm also unsure whether this is an issue with connected-react-router or a regression/problem that should be fixed in react-router but I wanted to get your input. Thanks!

@filoxo
Copy link
Author

filoxo commented Dec 13, 2018

For additional context, I have to use that version of react-router because of issues with react-router Routes unable to properly handle React.lazy() components. The fix (remix-run/react-router#6417) for that problem was merged but a new release hasn't been made yet.

@filoxo
Copy link
Author

filoxo commented Dec 13, 2018

Some additional info:

  • Using v4.3.1 works fine
  • I found a workaround by wrapping the ConnectedRouter in react-router's own BrowserRouter seems to have worked to silence the error, but of course, isn't ideal.

@mick-feller
Copy link

i am facing the same problem...

@iamlasse
Copy link

I'm using React Router 4.4 because of Routes accepting array paths, ConnectedRouter breaks with errors that you cant use route or link outside of a browser. But I am not changing how I'm connecting the router, and only updated to latest React Router.

@wildfrontend
Copy link

same problem +1

when i use jest test it happened

@supasate
Copy link
Owner

@filoxo I saw your codesandbox uses react-router-dom@4.4.0-beta.6, but, uses react-router@4.3.1.

image

I created a test repo here https://github.com/supasate/test-react-router-4.4.0 and it works well by using react-router and react-router-dom v4.4.0-beta.6. I saw the error appeared if I change one of that to 4.3.1.

However, even though my repo works well on my local machine, when I imported it to Codesandbox, it shows the same error. I guess, on Codesandbox, the Link component may import react-router from a different location of the main react-router used in the repo, and Link needs Context from react-router, so, it may get a different context.

Please let me know if it still happens on your local machine and please provide a repo that I can clone and test on my machine.

@supasate
Copy link
Owner

Closing for now. If anyone still has this issue, feel free to add more comments and provide some minimal reproducible github repo.

@houmingjie
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants