Skip navigation
SPA mode in Next.js?
0:00 / 0:21

SPA mode in Next.js?

Alex Sidorenko

@asidorenko_35K followers

Visit on X
348 likesDownloadOriginal post

43,463 views

SPA mode in Next.js?

9 Comments

Comments from the original post on X (Twitter)

  • Alex Sidorenko's profile picture

    @asidorenko_

    This is the static export - the closest thing to SPA in Next. Unlike classical SPA (with one index.html page), the static export pre-generates all routes into HTML files during the build time. Like SPA, it can be hosted on any server that can serve static assets.

    5 likes

  • Alex Sidorenko's profile picture

    @asidorenko_

    The navigation happens on the client. We can fetch dynamic data with useQuery/SWR in client components. We can even fetch static data in server components - it will get fetched during the build time.

    4 likes

  • Alex Sidorenko's profile picture

    @asidorenko_

    At the moment, dynamic routes need to be pre-generated using generateStaticParams for static exports. However, there is a proposal for serverless navigation, which could potentially remove this limitation.

    7 likes

  • Benzigar Alvin.'s profile picture

    @benzigar_alvin

    Disclaimer : For SPA, go for @reactjs . Next is not built for that. And build export will not work in next unless there is not server side code..

    2 likes

  • Wojciech Maj 🦋 @wojtekmaj.pl's profile picture

    @wojtekmaj91

    That sounds like Vite with extra steps

    2 likes

  • Chuangcius's profile picture

    @chuangcius

    I've been waiting SPA in next.js for quite a while, will it come someday?

    1 like

  • Alex Sidorenko's profile picture

    @asidorenko_

    Well, this is it. Static export generates static files, so it works like SPA. It's even better as it pre-generates HTML for all routes, not only index.html. However, the dynamic routes are the missing piece of the puzzle right now.

    2 likes

  • Rahul's profile picture

    @rahulpeacock

    If you want to deploy a next.js app using cloudflare, then this will be very helpful

    1 like

  • Wael Assaf's profile picture

    @waelnassaf

    Yes That's a static export