首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React导航v5:如何与Branch.io一起使用

React导航v5:如何与Branch.io一起使用
EN

Stack Overflow用户
提问于 2020-10-27 06:37:15
回答 1查看 1.4K关注 0票数 1

我们有一个利用Branch.io通用链接的应用程序。遵循上的文档:https://help.branch.io/developers-hub/docs/react-native#read-deep-link

在react原生应用程序上,您可以设置一个订阅者,以便在javascript运行时接收深度和通用链接。

从这里使用最新的react-navigationhttps://reactnavigation.org/docs/deep-linking

React Navigation希望本机处理深度链接。React Navigation似乎不会公开手动启动链接的好方法。

如何同时使用这两个服务?事实证明,采用深度链接并将其分解为可路由的深度链接是具有挑战性的。我们的应用程序嵌套了路由器,重做从路径到屏幕和参数的转换是我不想做的事情。最近有人这么做过吗?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-27 06:55:08

您可以使用subscribe选项通知React导航有关传入链接的信息:

代码语言:javascript
复制
const linking = {
  // Custom susbcription to handle incoming links
  subscribe(listener) {
    branch.subscribe(({ error, params, uri }) => {
      if (error) {
        console.error('Error from Branch: ' + error);
        return;
      }

      if (params['+non_branch_link']) {
        const nonBranchUrl = params['+non_branch_link'];
        // Route non-Branch URL if appropriate.
        return;
      }

      if (!params['+clicked_branch_link']) {
        // Indicates initialization success and some other conditions.
        // No link was opened.
        return;
      }

      // A Branch link was opened
      const url = params.$canonical_url;

      listener(url);
    });

    return () => {
      // Clean up the event listeners
      branch.unsubscribe();
    };
  },
  // Options such as prefixes, screens config etc.
  // ...
};

文档:https://reactnavigation.org/docs/deep-linking/#third-party-integrations

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64545934

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档