首页 > 解决方案 > React Native Webview 将参数添加到本地 URI

问题描述

我正在使用带有本机反应的本地 SPA,webview并且我正在尝试向它发送一个参数,以便它可以使用该参数加载。

我已将源添加如下

let source = (Platform.OS === 'android' ? 'file:///android_asset/' : '') + 'SPA/index.html';

这是处理 android 和 iOS 但每当我添加?例如,如果我添加一个参数,我会在此服务器上找不到 URI

let source = (Platform.OS === 'android' ? 'file:///android_asset/' : '') + 'SPA/index.html?parameter=foo';

或者如果我添加

let source = (Platform.OS === 'android' ? 'file:///android_asset/' : '') + 'SPA/index.html/parameter=foo';

编辑:

我正在使用来源

<WebView
      originWhitelist={["file://"]}
      useWebKit={true}
      onMessage={this.invoke.listener}
      source={{
        uri: source
      }}
      style={{ marginTop: 20, flex: 1, backgroundColor: 'transparent' }}
      bounces={false}
      scrollEnabled={false}
      overScrollMode={'never'}
    />

标签: react-nativereact-native-webview

解决方案


推荐阅读