# 错误：路径 '/[slug]' 的静态生成失败，因为 'generateStaticParams' 没有为 slug '...' 返回值

- **ID:** `nextjs/static-generation-failed-for-dynamic-path`
- **领域:** nextjs
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

generateStaticParams 函数缺失或不完整，因此 Next.js 在构建时无法为动态路由静态生成页面。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| next@13.4.0 | active | — | — |
| next@14.0.0 | active | — | — |
| next@14.2.10 | active | — | — |

## 解决方案

1. ```
   实现 generateStaticParams 以返回所有可能的 slug 值数组。如果数据源是动态的，请使用 fetch 或数据库查询。
   ```
2. ```
   如果 slug 数量太大，请使用增量静态再生（ISR），在 fetch 或页面配置中添加 revalidate。
   ```
3. ```
   使用动态渲染，设置 `export const dynamic = 'force-dynamic'` 以完全跳过静态生成。
   ```

## 无效尝试

- **** — The page will be generated for the dummy slug but still fail for other slugs if they are accessed. (80% 失败率)
- **** — This will cause a 404 for any slug not pre-generated, which is not the intended fix. (90% 失败率)
- **** — This changes the application structure and may break existing functionality. (95% 失败率)
