[英]Opening DeepLinks which are not specified in Routes in react-native
If i consider an example 如果我考虑一个例子
https://app.abc.com/login
this opens login page in my app. 这会在我的应用中打开登录页面。 But if the link is like
但如果链接是这样的
https://app.abc.com/loginUser //This link is a route in web app
this doesn't open the login page in App because the Path is not defined in routes 这不会在App中打开登录页面,因为Path未在路径中定义
Now the requirement is, whenever a user clicks on Second link, even then it should open login component in App and not in web. 现在的要求是,每当用户点击第二个链接时,即使这样,它也应该在App中而不是在Web中打开登录组件。 ie.
即。 multiple routes for same component, or can i open a generic component for such routes?
同一组件的多个路由,或者我可以为这些路由打开通用组件吗? Can we achieve this in React-Native?
我们能在React-Native中实现这一目标吗?
This was pretty simple, just had to explore documentation of React-Navigation 这很简单,只需要探索React-Navigation的文档
import { NavigationActions } from 'react-navigation'
const previousGetActionForPathAndParams = MyAPP.router.getActionForPathAndParams;
Object.assign(MyApp.router, {
getActionForPathAndParams(path) {
console.log("path in navigation", path)
if (
path === 'loginUser'
) {
// returns a profile navigate action for /my/custom/path
return NavigationActions.navigate({
routeName: 'Login',
});
}
// else {
// console.log("you have landed in an unknown space")
// }
return previousGetActionForPathAndParams(path);
},
});
Insert this code in your navigation file and you are good to go with React-Navigation 在导航文件中插入此代码,您最好使用React-Navigation
In previous versions, we could do that by giving multiple paths to a specific component as per here 在以前的版本中,我们可以通过在此处为特定组件提供多个路径来实现
Thanks to @DoğancanArabacı for a valuable comment, that once used to be a handy solution 感谢@DoğancanArabacı的有价值的评论,曾经是一个方便的解决方案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.