反应导航推屏在另一个选项卡中
我的标签导航器和堆栈导航器如下所示:
- Tab_1
-------- Stack_1
-------- Stack_2
-------- Stack_3
- Tab_2
我想从内部stack_2
从tab_2
带有ID参数。
我可以使用
navigation.navigate("Tab_1", {screen: "stack_2", params: {id: "abcd"}})
,但是如果我想再次使用ID EFGH
再次导航,则不会刷新屏幕。如果我在堆栈导航器内部,我会很容易地使用PUST,但是当我在另一个选项卡中时,我无法使用它。
到目前为止,我已经尝试了
navigation.reset({ index: 0, routes: [{ name: "Tab_1", params: { screen: "Stack_2", params: { id: "abcd" } } }] });
这项工作,但是我无法转到stack_1
,这是tab_1
的主屏幕,因为返回按钮未显示,也可以按下TAB_1
图标什么都不做。
如何从此处的另一个选项卡中获得与navigation.push
相同的结果?
I have tab navigators and stack navigator nested as follows:
- Tab_1
-------- Stack_1
-------- Stack_2
-------- Stack_3
- Tab_2
I want to navigate to Stack_2
from inside Tab_2
with id parameters.
I can use
navigation.navigate("Tab_1", {screen: "stack_2", params: {id: "abcd"}})
but this won't refresh the screen if I want to navigate again with id efgh
. I would easily use push if I was inside the stack navigator, but as I am inside another tab I can't use that.
So far I have tried
navigation.reset({ index: 0, routes: [{ name: "Tab_1", params: { screen: "Stack_2", params: { id: "abcd" } } }] });
This does the job but then I can't go to Stack_1
which is the main screen of Tab_1
as the back button does not appear and also pressing on Tab_1
icon does nothing.
How can I achieve the same result as navigation.push
in here from inside another tab?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在
stack.screen 上使用
getID
:这告诉React Navigation添加新ID的新屏幕,即您想要的行为。
https://reactnavigation.org/docs/screen/screen/screen/#getid
You can use the
getId
prop onStack.Screen
:This tells React Navigation to add a new screen for the new ID, which is the behavior you want.
https://reactnavigation.org/docs/screen/#getid
推动的另一种方法是重置状态,这意味着向子堆栈的路线添加新路线:
重置方法,您可以更新选项卡状态的详细信息。
Another way to push is to reset the state, which means to add a new route to the child stack's routes:
by the reset method, you can update the details of your tab state.