作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们有一个使用 Branch.io 通用链接的应用程序。遵循以下文档: https://help.branch.io/developers-hub/docs/react-native#read-deep-link
在 react-native 应用程序上,您设置订阅者以在 javascript 运行时接收深度和通用链接。
从这里使用最新的 react-navigation
:https://reactnavigation.org/docs/deep-linking
React Navigation 希望原生处理深度链接。 React Navigation 似乎没有提供手动启动链接的好方法。
如何同时使用这两项服务?采用深层链接并将其分解为可路由的深层链接被证明具有挑战性。我们的应用程序有嵌套的路由器,重做从路径到屏幕和参数的转换是我不想做的事情。最近有没有人做过这个?谢谢。
最佳答案
您可以使用 subscribe
选项通知 React Navigation 有关传入链接的信息:
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
关于react-native - react 导航 v5 : How to use with Branch. io,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64545934/
我是一名优秀的程序员,十分优秀!