-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
NavLink used in module causes Invariant Violation: You should not use <Route> or withRouter() outside a <Router> #6747
Comments
You have to be using the exact same instance of React Router because of how the new Context API works behind the scenes. This is actually indicative that you are including two copies of React Router too. Depending on your build tooling, you should mark React Router as external and export it to that sidebar library. |
@timdorr - Can you show how to do that? with webpack. |
For someone would fell into the same trap. I did this for now to get worked: Pass the 'NavLink' from the project to the |
@zhangriyueming Check your webpack / rollup / whatever config. If you use webpack, this gist of mine might help: https://gist.github.com/StringEpsilon/88c7b049c891425232aaf88e7c882e05 |
This might be of help too: |
For Library Authors use externals if you are using webpack |
Version
5.0.0
Test Case
Steps to reproduce
<Sidebar>
with list of<NavLink>
.<Router>
at root level. And put some<Route>
to different controllers.<Sidebar>
Invariant Violation: You should not use <Route> or withRouter() outside a <Router>
Expected Behavior
Works without errors.
If move the
<Sidebar>
component to the project itself, it will works fine. But if put<Sidebar>
component to a module, it causes the error.Actual Behavior
Invariant Violation: You should not use <Route> or withRouter() outside a <Router>
The text was updated successfully, but these errors were encountered: