深层链接 - 如果应用程序关闭则不起作用

问题描述

我正在我的本机应用程序中实现与 expo 的深度链接。我设法使用带有 this tutorialthis documentation代码将其调整为我的嵌套堆栈:

const linking = {
  prefixes:[prefix],config: {
    screens: {
      Drawer: {
        screens: {
          Tabs: {
            screens: {
              Profile:"profile"
            }
          }
        }
      },}
  }
}
return (
  <NavigationContainer linking={linking}>
    <RootStackScreen actions={actions} showLoader={showLoader} user={user} {...props} />
  </NavigationContainer>
)

}

如果我使用 myscheme://profile,它会按预期工作,但前提是应用程序在后台打开。当应用程序关闭时,它只是在我的初始主屏幕中打开它,我尝试谷歌搜索搜索,但找不到任何适合我所做的解释。我还尝试将 getinitialRoute 函数添加linking,该函数在应用关闭并从深层链接打开时触发,但不知道如何使用它来激活导航。>

async getinitialURL() {
  const url = await Linking.getinitialURL(); // This returns the link that was used to open the app
  if (url != null) {
    //const { path,queryParams } = Linking.parse(url);
    //console.log(path,queryParams)
    //Linking.openURL(url) 
    return url;
  }
  
},

解决方法

您可以检查几件事。

  • 验证 linking.config 的结构是否与您的导航结构相匹配。我过去遇到过类似的问题,并通过确保我的 config 结构正确来解决它。

  • 确保正确设置 linking 对象。请参阅 docs 进行验证。从它的外观来看,您展示的 linking 对象中没有 getInitialURL 属性。

  • 确认您已将事物的本机方面设置为 documented

希望一切顺利!如果没有,请告诉我。 ?

,

我想您确认在您的应用程序启动时调用了您的函数 getInitialURL 吗?此外,if (url != null) { 中的注释代码不应该被注释对吗?

如果以上没有问题,那么问题可能与启用的调试器有关。根据 React Native 的文档 (https://reactnative.dev/docs/linking#getinitialurl):

getInitialURL 可能会在启用调试时返回 null。禁用调试器以确保它通过。

,

您是在发布版本中构建吗?在我的应用程序中,在调试中从退出状态进行深层链接不起作用,但在发布中按预期工作