nextjs
runtime_error
ai_generated
true
错误:revalidatePath('/path') 失败。该路径与任何现有路由不匹配。
Error: revalidatePath('/path') failed. The path does not match any existing route.
ID: nextjs/revalidate-path-not-found
92%修复率
88%置信度
1证据数
2024-03-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| [email protected] | active | — | — | — |
| [email protected] | active | — | — | — |
根因分析
revalidatePath 函数被调用时使用的路径与 app 目录中的任何路由不匹配,通常是由于拼写错误或动态路由段不匹配。
English
The revalidatePath function is called with a path that does not correspond to any route in the app directory, often due to a typo or mismatch in dynamic route segments.
官方文档
https://nextjs.org/docs/app/api-reference/functions/revalidatePath解决方案
-
Verify the exact route structure in the app directory. For dynamic routes like [slug], use the actual slug value in the path, e.g., revalidatePath('/posts/my-post'). Use revalidatePath('/posts/[slug]') only if you want to revalidate all pages with that pattern. -
Use revalidateTag instead of revalidatePath if you have tagged the fetch calls with a specific tag.
无效尝试
常见但无效的做法:
-
70% 失败
revalidatePath does not support query parameters; it only matches the pathname. Including query strings will cause a mismatch.
-
60% 失败
revalidatePath is asynchronous and must be awaited to ensure the revalidation completes. Without await, the error may be swallowed.