-
-
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
Broken SSR: You should not use <Link> outside a <Router> when I'm clearly using <Link> inside a <Router> #6789
Comments
Similar issue - fixed by downgrading |
Downgrading |
OK, so you're using two instances of the Router context pair. (Side note: I'll explain things fully here, but I'm going to have to turn this into a saved response...) There is a new In your server, you're importing from your build output and from the How you solve this is up to you. The most ideal option is to not import your bundle, but import from One thing to add: This isn't fundamentally a React Router or even a React problem. Anything that uses a singleton module would be affected by this if you reference that singleton in your bundle and your server separately. It's the nature of JS itself, so the fixes I suggest are best for avoiding problems with other libraries as well. |
Take a look at my answer for a possible solution here: |
Exporting |
Version
V5.0.1
Test Case
https://github.com/modsoussi/react-ssr
Steps to reproduce
git clone https://github.com/modsoussi/react-ssr.git
cd react-ssr
npm i
npm start
localhost:5000/
Expected Behavior
Expect app to render. This is the code for
App
:On the client, it's rendered inside a
BrowserRouter
, and on the server it's rendered inside aStaticRouter
.Actual Behavior
renderToStaticMarkup(app)
fails and throwsError: Invariant failed: You should not use <Link> outside a <Router>
.The text was updated successfully, but these errors were encountered: