Linking.getInitialURL 不断被执行,应用程序被复制 [英] Linking.getInitialURL constantly being executed and app being duplicated
问题描述
对不起,冗长的标题.
这是我的 componentDidMount()
函数
componentDidMount() {
Linking.getInitialURL().then(data => {
console.log(data);
});
}
当我启动我的应用程序时,data
正确地设置为 null
.
When I boot up my app, data
is rightfully set to null
.
然后用户通过 Google Chrome 登录,该 Chrome 浏览器通过
A User then logs in via Google Chrome which is opened via
Linking.open('https://...);
当用户被重定向回我的应用程序时,我可以看到 data
已被填充.这一切都很好.
When the User gets redirected back to my app, I can see that data
has been populated. This is all well and good.
但是,当我被重定向回来时,我看到了重复的组件.这是 React Native Debugger 的屏幕截图.我有
和
However, when I am redirected back, I see duplicate components. Here's a screenshot from the React Native Debugger. I have <AppContainer root=1..>
and <AppContainer root=11..>
由于这种重复,我的应用程序调用了 componentDidMount()
两次,并且多次调用了 Linking.getInitialURL()
.
Because of this duplication, my app calls componentDidMount()
twice and Linking.getInitialURL()
is called multiple times.
此外,如果我通过开发者菜单刷新应用程序,从 Linking.getInitialURL
的承诺返回的 data
仍会填充,而它应该是 null代码>.
Furthermore, if I refresh the app via the developer menu, the data
returned from Linking.getInitialURL
's promise is still populated when it should be null
.
推荐答案
解决这个问题的方法是将 android:launchMode="singleTask"
添加到我的 .MainActivity
活动.
The solution to this problem was to add android:launchMode="singleTask"
to my .MainActivity
activity.
在 this Github 线程上找到的解决方案.
Solution found on this Github thread.
这篇关于Linking.getInitialURL 不断被执行,应用程序被复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!