No, it can't create a fully client side SPA (a single document app) without having to ship a Node server with your app. Unless you use something like next-export which generates a bunch of HTML files at build time and is not the same thing as a SPA (one HTML file).
Next is doing exactly what you are asking it to do. next-export implies that you don't want to use Next Router. So if you write multiple page files in the /pages directory, Next gives you multiple pages, exactly as you instructed. If you want to connect those pages together, you write your own router lah, because you explicitly said that you don't want Next Router.
If you want one page SPA, you make only one file in the pages directory, and write your app exactly like in vite (that one page has only the App component and the router, e.g. react-router that links to other page components from the /components directory). You get exactly what you asked for. It's not Next's fault that you don't understand what you yourself wrote.
What? That is exactly why I'm saying that there is no ideal way to create a fully client-side SPA (that can be hosted on an S3 bucket) using just Next.js and why Vite provides a good intermediate solution for those uses cases.
If you're building a dynamic SPA with Next you'll probably want to run it on a Node.js server (which is totally fine) but you don't need that with a Vite-based SPA. Not every project needs the added complexity and overhead from additional infra.
A bunch of HTML files is still an SPA — just a better one. It behaves like an SPA in all other ways (and is more efficient because it splits code by route). The one trickier part is deployment (need a rewrite map) but it’s perfectly possible to host it statically: https://gist.github.com/gaearon/9d6b8eddc7f5e647a054d7b333434ef6
I get that you and the React team have your reasons to push Vercel products, but a Vite-based SPA will always be easier to host and has more flexible routers for rich applications.
3
u/neg_ersson Mar 18 '23 edited Mar 18 '23
No, it can't create a fully client side SPA (a single document app) without having to ship a Node server with your app. Unless you use something like
next-exportwhich generates a bunch of HTML files at build time and is not the same thing as a SPA (one HTML file).