You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React-router-native报错:_react.PropTypes.func未定义不是对象

问题定位

这个报错和你的业务代码无关,属于依赖版本兼容问题。
React 自16.0版本起就将PropTypes从核心库中拆分到独立的prop-types包,React核心不再暴露React.PropTypes相关API。你当前安装的react-router-native版本过低,仍在引用已被移除的React.PropTypes.func,因此抛出该错误。移除相关引入后报错消失,也能佐证问题出在依赖包本身而非你的业务逻辑。

修复步骤
  • 首先卸载当前旧版本依赖,安装适配新版React Native的v6系列稳定版:
npm uninstall react-router-native
npm install react-router-native@6 react-router@6
  • 修正路由配置代码:v6版本的Route组件默认采用精确匹配规则,已经移除了exact属性,需要删除代码里的冗余exact标识,调整后代码如下:
<Routes>
  <Route path="/" element={<RepositoryList />} />
  <Route path="/signIn" element={<SignIn />} />
</Routes>
  • 修正App组件结构:路由上下文只能覆盖<NativeRouter>包裹的内部组件,你当前写在NativeRouter外层的<RepositoryList />无法获取路由状态,建议将所有路由相关内容都放在NativeRouter内部,参考写法:
import { NativeRouter, Routes, Route } from "react-router-native";

const App = () => {
  return (
    <NativeRouter>
      <Routes>
        <Route path="/" element={<RepositoryList />} />
        <Route path="/signIn" element={<SignIn />} />
      </Routes>
    </NativeRouter>
  )
};
  • 若因项目历史原因必须使用5.x及更早版本的react-router-native,要么将React Native降级到依赖React 15的极旧版本,要么使用patch-package修改node_modules中对应依赖的PropTypes引用方式,两种方式维护成本都很高,不推荐使用。

内容的提问来源于stack exchange,提问作者The_elevator

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.02 03:18:24