gpt4 book ai didi

react-native - React Native Webview 处理 url 更改监听器

转载 作者:行者123 更新时间:2023-12-04 05:17:54 24 4
gpt4 key购买 nike

可以在 React Native Web View 上处理 URL 更改。

我尝试处理 onNavigationStateChange听众。但它只有一次发射。当页面加载时触发 onNavigationStateChange。当我导航到另一个页面时,此事件不会触发。

任何的想法?

最佳答案

引用import { WebView } from 'react-native-webview'请尝试关注 code/method获取当前导航 path/url因为在你的情况下 onNavigationStateChange这可能不会返回导航路径,因此您可以尝试 onLoadProgress .
而不是这个

 onNavigationStateChange={(state) => {
console.log("current_path",path);

}}
试试这个
这可能会被多次调用,请相应地处理您的情况。
 onLoadProgress={({ path}) => {
console.log("current_path",path);
}}

This is how my WebView looks like

  <WebView
source={{ uri: this.state.url }}
onLoadEnd={() => this.hideSpinner()}
onMessage={onMessage.bind(this)}
ref={WEBVIEW_REF => (this.WebViewRef = WEBVIEW_REF)}
startInLoadingState={true}
javaScriptEnabled={true}
domStorageEnabled={true}
onLoadProgress={({ nativeEvent }) => {
//your code goes here
}}
onNavigationStateChange={(state) => {
//your code goes here
}}
/>

关于react-native - React Native Webview 处理 url 更改监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38807352/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com