意外地回到嵌套导航的反应导航
我面临React-Native 0.66.4
和React-Navigation 4.4.4
的导航问题。 我有一个看起来像这样的标签导航设置。
- 标签导航
主页
- 屏幕a(intial)
- 屏幕B
交易
- 屏幕1(Intial)
- 屏幕2
- 屏幕3
屏幕1引导到2或3
我试图从Home Tab(屏幕A)到交易选项卡(屏幕2和屏幕3)使用单独的按钮,我能够通过执行navigation.navigate('trade',{屏幕:'screen2',params:{...}})
and navigation.navigate('trade',{屏幕:'screet 3' ,params:{...}})
我现在面临的问题是
当我导航到Trade(Screen2)并使用返回按钮时,它会导航到Home(ScreenA)
导航到交易(screen3),然后使用“返回”按钮go 这种方式交易(screen3)=>贸易(屏幕2)=>家(Screena),和 像这样的交易(screen2)=>贸易(屏幕3)=> Home(Screena)如果 我首先访问了屏幕3,要实现此目标,我必须点击返回 两次。
最后,如果我在单击之前访问了屏幕2或3 “交易”选项卡,它显示屏幕而不是屏幕1(初始)。 这不是我正在寻找的行为。
我该怎么做,以使每当我从交易(屏幕2或屏幕3)返回时,它会导航到交易(屏幕1),并且在访问这些屏幕中的任何一个(2和3)之后,也单击“交易”选项卡(2和3)导航到屏幕1(初始)?
我怎么能
I am facing a navigation issue in react-native 0.66.4
and react-navigation 4.4.4
.
I have a Tab Navigation setup that looks like this.
- Tab Navigation
Home
- Screen A(Intial)
- Screen B
Trade
- Screen 1 (Intial)
- Screen 2
- Screen 3
Screen 1 Leads to 2 or 3
I am trying to navigate from Home Tab (Screen A) to Trade Tab (Screen 2 and Screen 3) using separate buttons, I am able to achieve that by doing navigation.navigate('Trade', { screen: 'Screen2', params:{...} })
and navigation.navigate('Trade', { screen: 'Screen3', params:{...} })
The issue I am facing now is that
When I navigate to Trade (Screen2) and use the back button, it navigates to Home (ScreenA)
Navigating to Trade (Screen3) and then using the back button goes
this way Trade(Screen3) => Trade(Screen 2) => Home(ScreenA), and
like this Trade(Screen2) => Trade(Screen 3) => Home(ScreenA) if
I visited Screen 3 first and to achieve this I have to click back
twice.Finally, if I have visited Screen 2 or 3 before clicking on
the Trade Tab, it shows that screen rather than Screen 1 (Initial).
This is not the kind of behavior I am looking for.
How can I do it such that whenever I go back from either Trade (Screen 2 or Screen 3),it navigates to Trade (Screen1), and also clicking the Trade Tab after visiting either of these screens ( 2 and 3) navigates to Screen 1 (initial)?
How can I na
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您使用嵌套堆栈从一个选项卡导航到另一个选项卡时,您将需要传递初始参数:false参数,以防止首页被视为初始参数。
然后,当您在Screen2上按GOBACK()时 - 它将上堆栈到屏幕1(初始)
When you navigate from one tab to another tab with a nested stack, you will need to pass the initial: false parameter to prevent the first page from being considered the initial.
Then when you press goBack() on Screen2 - it will go up the stack to screen 1 (initial)
为了实现这一目标,我认为您可以使用官方文档中指定的 InitialRoutename 支柱(检查 stacknavigatorConfig )。请尝试一下,让我知道情况如何。
https://reaectnavigation.org/docs/4.x/stack-navigator
您可以为这些屏幕进行测试吗?创建一个按钮, OnPress 做
,请让我知道一切正常。我没有我的开发环境,所以我只是从参考中写这篇文章。
To achieve this I think you can use the initialRouteName prop as specified in the official docs(check StackNavigatorConfig). Please try that and let me know how it goes.
https://reactnavigation.org/docs/4.x/stack-navigator
Can you do a test for these screens? Create a button and onPress do
and please let me know if everything works fine. I don't have my development environment with me so I'm writing this just from reference.
我设法使用'avaigation-state' https://reactnavigation.org/docs/navigation. -State/
“状态”中给定项目的任何列表,您只需要粘贴到当前的前一个,然后重定向到它。
I managed to solve my problem using 'navigation-state' https://reactnavigation.org/docs/navigation-state/
Any list of a given item in the 'state', you only need to paste to the previous one that is currently and redirect to it.