ShakaCode | ShakaCode Blog | Rails On Maui Blog | Rails | ReactJs | JavaScript | Webpack | Productivity |

React Router v4 + SSR = :(


#1

Hello!

I am having hard time trying to use RR v4 when rendering the app on the server. I managed to get it working to some extent—the routes do change but each navigation request triggers a page reload. I don’t think that it should behave like that (or maybe it should?), but can’t find any info on how to fix that. The docs for this subject are outdated (RR API has changed; there’s even an issue for that, #809, but left untouched).

Here’s a video showing how the app behaves (production build): https://v.usetapes.com/vx6mKGuXcT. There are 2 apps, one is SSR-ed (landing + login + signup pages) and one is rendered on the client (platform part). Navigating between the apps does reload the page and that’s fine. But I would presume that doing so inside the boundaries of each app will behave exactly the same (no page reload), regardless of it being SSR-ed or not.

Code: https://gist.github.com/mtunski/11a662814b488b97e434b9a4f073cce5.

Let me know if I need to provide any additional info. Any help would be appreciated!

— EDIT:

I have found out why it didn’t work. I have not included my client-side bundle in the markup :scream:. Behaves correctly after this fix :sweat_smile:.