我们有一个利用 Branch.io 通用链接的应用程序。按照以下文档:https://help.branch.io/developers-hub/docs/react-native#read-deep-link https://help.branch.io/developers-hub/docs/react-native#read-deep-link
在react-native应用程序上,您设置了一个订阅者来接收javascript运行时中的深层通用链接。
使用最新的react-navigation
从这里:https://reactnavigation.org/docs/deep-linking https://reactnavigation.org/docs/deep-linking
React Navigation 希望原生处理深层链接。 React Navigation 似乎没有提供手动启动链接的好方法。
我如何同时使用这两项服务?事实证明,获取深层链接并将其分解为可路由的深层链接具有挑战性。我们的应用程序具有嵌套路由器,并且重新进行从路径到屏幕和参数的转换是我不想做的事情。最近有人这样做过吗?谢谢。
您可以使用以下命令通知 React Navigation 有关传入链接的信息subscribe
option:
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.
// ...
};
Docs: https://reactnavigation.org/docs/deep-linking/#third-party-integrations https://reactnavigation.org/docs/deep-linking/#third-party-integrations
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)