colinhacks / nextjs-react-router

A demonstration of how to use React Router inside Next.js
https://vriad.com/essays/building-a-spa-with-nextjs
146 stars 27 forks source link

Won’t work for static export #7

Open MarkWestside opened 1 year ago

MarkWestside commented 1 year ago

As redirects are not possible for static HTML export, / (or index.html) will just return a blank page.

eric-burel commented 11 months ago

When exporting you may need whatever server you end up using to do a redirection like demoed in next.config.js. For instance if hosting on Vercel, you have a similar configuration specific to Vercel. Locally I think you can tweak  serve to do that, see https://github.com/vercel/serve-handler#options

MarkWestside commented 11 months ago

I’m talking about standard web servers where you don’t have control over redirects or routing. Imagine a learning management system where you upload the static HTML export as a course.

eric-burel commented 11 months ago

I don't think they can host a normal SPA either then, you need a way to point any URL to index.html

I think you might need instaed an exported Next.js app that outputs one file per page, it works fine as long as you don't have dynamic routes (since you also need a rewrite to handle those)