Open colinhacks opened 4 years ago
Thanks @vriad, this approach was actually never recommended by Next.js team :). I highlighted this in the article but I forgot to do so in the repo. I just updated the readme and I'll archive the repo, too.
BTW very happy and surprised to know how you made good use of this adventurous experiment.
Cheers! 🙌
PSA for the community: since the release of Next.js 9.5 the custom server (
/server.js
) approach to this is no longer recommended by the Next.js team. Instead you should userewrites
innext.config.js
. [EDIT: It was never recommended 😛]I wrote up a detailed guide on how to do this with v9.5+ (it's still surprisingly tricky): Building a SPA with Next.js and React Router. You can also see a working example in this repo. Happy hacking!
@toomuchdesign — thanks for the great resource! I used this approach for several projects back in 2019. Though since this repo ranks highly on Google for "nextjs react router" and similar queries, it might make sense to refactor the code to use rewrites or add a notice in the README so people don't write a custom server unnecessarily. Thanks again for your great work on this! 🤙