# 类型错误：无法读取 undefined 的属性（读取 'params'）

- **ID:** `react/typeerror-cannot-read-properties-of-undefined-reading-params`
- **领域:** react
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

代码尝试访问路由参数（例如 `useParams()` 或 `match.params`），但组件未在 Route 上下文内渲染，或路由路径未定义预期的参数。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| React Router 6.20.0 | active | — | — |
| React Router 5.3.4 | active | — | — |
| React 18.2.0 | active | — | — |

## 解决方案

1. ```
   Ensure the component is wrapped in a Route: `<Route path="/user/:id" element={<UserComponent />} />` and access params via `useParams()` hook inside UserComponent.
   ```
2. ```
   If using class component, use `withRouter` HOC (React Router v5) or wrap with `useParams` in a function component and pass as props.
   ```
3. ```
   Check that the route path includes the parameter (e.g., `/user/:id`) and the URL actually matches.
   ```

## 无效尝试

- **** — The underlying issue (component outside Router) remains, leading to other bugs. (90% 失败率)
- **** — Both exports exist, but the context provider difference is the real issue. (85% 失败率)
