# 错误：服务端操作已重定向但页面未重新验证。请在重定向前使用 revalidatePath 或 revalidateTag 以确保数据是最新的。

- **ID:** `nextjs/server-action-redirect-without-revalidate`
- **领域:** nextjs
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

服务端操作在修改数据后调用了 redirect()，但未先调用 revalidatePath() 或 revalidateTag()。Next.js 要求服务端操作在重定向前进行显式缓存重新验证，以防止显示过时数据。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Next.js 14.x | active | — | — |
| Next.js 15.x | active | — | — |

## 解决方案

1. ```
   在服务端操作中的 redirect() 之前调用 revalidatePath()。示例：'use server'; import { revalidatePath } from 'next/cache'; import { redirect } from 'next/navigation'; export async function updateData(formData) { // 修改数据 revalidatePath('/dashboard'); redirect('/dashboard'); }
   ```
2. ```
   如果您的 fetch 调用已添加标签，请使用 revalidateTag()。示例：revalidateTag('posts'); redirect('/posts');
   ```
3. ```
   如果不想重定向，请返回成功响应，让客户端在服务端操作完成后使用 router.push() 处理导航。
   ```

## 无效尝试

- **** — redirect() throws a NEXT_REDIRECT error that stops execution. Any code after redirect() will never run. revalidation must happen before the redirect call. (100% 失败率)
- **** — router.refresh() is a client-side method and cannot be called inside a Server Action. It also does not affect server-side cache invalidation. (95% 失败率)
- **** — This prevents caching but does not revalidate the specific path after mutation. The redirect will still work, but Next.js will still warn about missing revalidation, and the behavior is not guaranteed in future versions. (60% 失败率)
