再次渲染本机应用程序 Web 视图

Render again react-native application Web-View

我有一个带有 webview 的 react-native 应用程序。 我想在单击通知时转到预定义页面(导航到页面),但应用程序不呈现新视图。 这是我打开应用程序时的代码(没有通知点击):

return (
  <WebView
    automaticallyAdjustContentInsets={false}
    source={{
      uri: 'https://my-url/',
    }}
    javaScriptEnabled={true}
    domStorageEnabled={true}
    startInLoadingState={true}
    style={{
      marginTop: 25,
    }}
  />
); 

而且,当我点击通知时:

return (
  <WebView
    automaticallyAdjustContentInsets={false}
    source={{
      uri: 'https://my-url/new',
    }}
    javaScriptEnabled={true}
    domStorageEnabled={true}
    startInLoadingState={true}
    style={{
      marginTop: 25,
    }}
  />
);

当我点击通知时,应用程序再次在 https://my-url 中打开。

我想在点击通知时在 https:///my-url/new 上导航。

你能帮帮我吗?

使用状态为网络视图设置 url。当状态改变时,webview 将重新加载更新后的 url.

用 'https://my-url/'

初始化 url 状态

假设您正在使用 class 组件,在您的构造函数中设置初始 url.

constructor(props) {
    super(props);

    this.state = {
        url: 'https://my-url/'
    }
}

当你点击通知时,设置你想要的状态url。

onNotification: function(notification) {
    this.setState({
        url: 'https://my-url/new'
    })
}

这应该在 webview 中呈现预定义页面

return (
  <WebView
    automaticallyAdjustContentInsets={false}
    source={{
      uri: this.state.url,
    }}
    javaScriptEnabled={true}
    domStorageEnabled={true}
    startInLoadingState={true}
    style={{
      marginTop: 25,
    }}
  />
);