正在加载视频...

视频加载失败

SPA mode in Next.js?

43,459 次观看 • 2 年前 •via X (Twitter)

9 条评论

Alex Sidorenko 的头像
Alex Sidorenko2 年前

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.

Alex Sidorenko 的头像
Alex Sidorenko2 年前

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.

Alex Sidorenko 的头像
Alex Sidorenko2 年前

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.

Benzigar Alvin. 的头像
Benzigar Alvin.2 年前

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..

Wojciech Maj 🦋 @wojtekmaj.pl 的头像
Wojciech Maj 🦋 @wojtekmaj.pl2 年前

That sounds like Vite with extra steps

Chuangcius 的头像
Chuangcius2 年前

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

Alex Sidorenko 的头像
Alex Sidorenko2 年前

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.

Rahul 的头像
Rahul2 年前

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

Wael Assaf 的头像
Wael Assaf2 年前

Yes That's a static export

相关视频