# 错误：重写目标 '/X' 未找到。目标路径必须是有效的路由。

- **ID:** `nextjs/rewrite-destination-not-found`
- **领域:** nextjs
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

next.config.js 中的重写规则指向一个在应用程序中不存在或不是有效内部路径的目标路由（例如，缺少文件、路径拼写错误）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Next.js 13.4 | active | — | — |
| Next.js 14.0 | active | — | — |
| Next.js 14.2 | active | — | — |
| Next.js 15.0 | active | — | — |

## 解决方案

1. ```
   在目标路径创建缺失的路由文件。例如，如果目标是 '/blog/[slug]'，则创建 'app/blog/[slug]/page.tsx'。
   ```
2. ```
   更正目标路径以匹配现有路由。检查 'app' 或 'pages' 目录中的文件结构，并相应更新 next.config.js。
   ```
3. ```
   如果目标是外部 URL 或不存在的内部路径且应指向其他地方，则使用重定向代替重写。
   ```

## 无效尝试

- **** — Trailing slashes do not create a route; the destination must exist as a file or directory. The error persists because the underlying route is still missing. (80% 失败率)
- **** — The error is specifically about the destination, not the source. Modifying the source may change behavior but does not resolve the missing destination. (70% 失败率)
- **** — Rewrites are for internal routes; external URLs require redirects. The error explicitly states the destination must be a valid internal route. (95% 失败率)
