Dev*_*tra 7 javascript react-native react-navigation
如果我考虑一个例子
https://app.abc.com/login
Run Code Online (Sandbox Code Playgroud)
这会在我的应用中打开登录页面。但是如果链接像
https://app.abc.com/loginUser //This link is a route in web app
Run Code Online (Sandbox Code Playgroud)
这不会在App中打开登录页面,因为路径未在路线中定义
现在的要求是,每当用户单击“第二”链接时,即使这样,它也应该在App中而不是在Web中打开登录组件。即。同一组件有多个路由,还是可以为此类路由打开通用组件?我们可以在React-Native中实现吗?
这非常简单,只需探索React-Navigation的文档
\n\nimport { NavigationActions } from \'react-navigation\' \n const previousGetActionForPathAndParams = MyAPP.router.getActionForPathAndParams;\n\n Object.assign(MyApp.router, {\n getActionForPathAndParams(path) {\n console.log("path in navigation", path)\n if (\n path === \'loginUser\'\n ) {\n // returns a profile navigate action for /my/custom/path\n return NavigationActions.navigate({\n routeName: \'Login\',\n });\n }\n // else {\n // console.log("you have landed in an unknown space")\n // }\n return previousGetActionForPathAndParams(path);\n },\n });\nRun Code Online (Sandbox Code Playgroud)\n\n将此代码插入您的导航文件中,您就可以使用 React-Navigation
\n\n在以前的版本中,我们可以通过为特定组件提供多个路径来实现这一点,如下所示
\n\n感谢@Do\xc4\x9fancanArabac\xc4\xb1 的宝贵评论,这曾经是一个方便的解决方案
\n| 归档时间: |
|
| 查看次数: |
163 次 |
| 最近记录: |