netlify-frameworks
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFrameworks on Netlify
Netlify 上的框架使用
Netlify supports any framework that produces static output. For frameworks with server-side capabilities (SSR, API routes, middleware), an adapter or plugin translates the framework's server-side code into Netlify Functions and Edge Functions automatically.
Netlify 支持任何可生成静态输出的框架。对于具备服务端能力(SSR、API 路由、中间件)的框架,适配器或插件会自动将框架的服务端代码转换为 Netlify Functions 和 Edge Functions。
How It Works
工作原理
During build, the framework adapter writes files to — functions, edge functions, redirects, and configuration. Netlify reads these to deploy the site. You do not need to write Netlify Functions manually when using a framework adapter for server-side features.
.netlify/v1/构建过程中,框架适配器会将函数、边缘函数、重定向规则和配置文件写入 目录。Netlify 会读取这些内容完成站点部署。当你使用框架适配器实现服务端功能时,无需手动编写 Netlify Functions。
.netlify/v1/Detecting Your Framework
检测你的框架
Check these files to determine the framework:
| File | Framework |
|---|---|
| Astro |
| Next.js |
| Nuxt |
| Vite + React (SPA or Remix) |
| TanStack Start |
| SvelteKit |
你可以通过检查以下文件判断使用的框架:
| 文件 | 框架 |
|---|---|
| Astro |
| Next.js |
| Nuxt |
| Vite + React(SPA 或 Remix) |
| TanStack Start |
| SvelteKit |
Framework Reference Guides
框架参考指南
Each framework has specific adapter/plugin requirements and local dev patterns:
- Vite + React (SPA or with server routes): See references/vite.md
- Astro: See references/astro.md
- TanStack Start: See references/tanstack.md
- Next.js: See references/nextjs.md
每个框架都有特定的适配器/插件要求和本地开发模式:
- Vite + React(SPA 或带服务端路由):参考 references/vite.md
- Astro:参考 references/astro.md
- TanStack Start:参考 references/tanstack.md
- Next.js:参考 references/nextjs.md
General Patterns
通用模式
Client-Side Routing (SPA)
客户端路由(SPA)
For single-page apps with client-side routing, add a catch-all redirect:
toml
undefined对于使用客户端路由的单页应用,需要添加一条兜底重定向规则:
toml
undefinednetlify.toml
netlify.toml
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
undefined[[redirects]]
from = "/*"
to = "/index.html"
status = 200
undefinedCustom 404 Pages
自定义404页面
- Static sites: Create a in your publish directory. Netlify serves it automatically for unmatched routes.
404.html - SSR frameworks: Handle 404s in the framework's routing (the adapter maps this to Netlify's function routing).
- 静态站点:在你的发布目录下创建 文件,Netlify 会自动为未匹配的路由提供该页面。
404.html - SSR 框架:在框架的路由逻辑中处理404(适配器会将其映射到 Netlify 的函数路由)。
Environment Variables in Frameworks
框架中的环境变量
Each framework exposes environment variables to client-side code differently:
| Framework | Client prefix | Access pattern |
|---|---|---|
| Vite / React | | |
| Astro | | |
| Next.js | | |
| Nuxt | | |
Server-side code in all frameworks can access variables via or .
process.env.VARNetlify.env.get("VAR")不同框架向客户端代码暴露环境变量的方式不同:
| 框架 | 客户端前缀 | 访问方式 |
|---|---|---|
| Vite / React | | |
| Astro | | |
| Next.js | | |
| Nuxt | | |
所有框架的服务端代码都可以通过 或 访问环境变量。
process.env.VARNetlify.env.get("VAR")