小编Dan*_*iao的帖子

React-Native链接AddEventListener不起作用

嗨,我试图使用React-Native的链接库来收听链接更改,我按照https://facebook.github.io/react-native/docs/linking.html上的说明进行操作.我可以使用openURL打开外部URL,但Linking.addEventListener似乎不适合我.我复制了代码段:

componentDidMount() {
  Linking.addEventListener('url', this._handleOpenURL);
},
componentWillUnmount() {
  Linking.removeEventListener('url', this._handleOpenURL);
},
_handleOpenURL(event) {
  console.log(event.url);
}
Run Code Online (Sandbox Code Playgroud)

它不会给我一个错误,但是当应用程序打开外部URL时,不会调用_handleOpenURL.

我想知道为什么会这样,我该怎么做才能解决它?

react-native

19
推荐指数
2
解决办法
6123
查看次数

标签 统计

react-native ×1