问题描述
我正在尝试在 React Native 中实现深层链接功能,我遵循了 React Native 的官方文档,也遵循了 React Navigation 的文档。我已经更改了我的 AndroidManifest.xml 文件并根据文档添加了意图过滤器,如下所示:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.broWSABLE"/>
<data android:host="app" android:scheme="demo"/>
</intent-filter>
还将 android:lunchMode 更改为 android:launchMode="singleTask"
。
当我使用 npx react-native android
安装应用时,应用成功安装在用户设备上。
之后我运行 adb 命令来检查深层链接,我得到以下响应:
$ adb shell am start -W -a android.intent.action.VIEW -d "demo://app/chat/123" com.rndemo
Starting: Intent { act=android.intent.action.VIEW dat=app://whatsupp/chat/123 pkg=com.whatsupfire }
Warning: Activity not started,intent has been delivered to currently running top-most instance.
Status: ok
Activity: com.rndemo/.MainActivity
ThisTime: 0
TotalTime: 0
WaitTime: 19
Complete
这是我的链接配置:
const config = {
screens: {
Chat: {
screen: {
ChatStack: {
path: 'chat/:id',parse: {
toId: (id) => `${id}`,},};
const linking = {
prefixes: ['demo://','demo://app'],config: config,};
我使用的是 React Navigation V5,我在 NavigatorContainer 中的 App.js 中使用链接,这里要提到的重要一点是我使用的是使用 React Navigation 官方文档的身份验证流程,并且聊天是嵌套的在导航器中,但我也尝试访问 demo://app 并且 adb shell 返回与上述相同的响应。
解决方法
将链接道具添加到 NavigationContainer:
<NavigationContainer linking={linking} >