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

React Native WebView无法加载显示网页问题求助

React Native WebView 加载页面卡住的排查方案

你的代码本身没有语法错误,不需要额外依赖组件。页面一直加载无法显示可以从以下几个方向排查:

  • 检查网络权限配置

    • Android:确保AndroidManifest.xml中添加了网络权限
      <uses-permission android:name="android.permission.INTERNET" />
      
    • iOS:在Info.plist中确认App Transport Security(ATS)配置,HTTPS网页默认ATS允许访问,若存在特殊限制可添加目标域名的例外规则:
      <key>NSAppTransportSecurity</key>
      <dict>
        <key>NSAllowsArbitraryLoads</key>
        <false/>
        <key>NSExceptionDomains</key>
        <dict>
          <key>reactnative.dev</key>
          <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <false/>
          </dict>
        </dict>
      </dict>
      
  • 添加调试监听排查错误
    在组件中加入加载相关回调,打印具体错误信息定位问题:

    import React from "react";
    import { View } from 'react-native';
    import { WebView } from 'react-native-webview';
    
    const WebViewComponent = () =>{
      return (
        <WebView 
          source={{ uri: 'https://reactnative.dev/' }} 
          style={{ flex: 1 }}
          onError={(syntheticEvent) => {
            const { nativeEvent } = syntheticEvent;
            console.warn('WebView加载错误:', nativeEvent);
          }}
          onLoad={() => console.log('WebView开始加载')}
          onLoadEnd={() => console.log('WebView加载结束')}
        />
      );
    }
    
    export default WebViewComponent;
    
  • 验证版本兼容性并重新构建
    确保react-native-webview版本与当前React Native版本匹配,可重新安装依赖后重建项目:

    npm uninstall react-native-webview
    npm install react-native-webview
    

    Android端执行./gradlew clean,iOS端执行pod install后重新运行项目。

  • 测试其他HTTPS页面
    尝试加载https://google.com这类通用HTTPS页面,如果能正常显示,说明是目标网站的适配问题;如果仍无法加载,则是本地环境或配置存在问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 20:17:12