英文:
Removing screen from Stack after navigating to another screen
问题
我有一个包含两个标签的 TabNavigator,分别是 "A 标签" 和 "B 标签"。
在 "B 标签" 中,有一个 StackNavigator,名为 "C 栈"。在这个堆栈内,我通过 navigation.navigate('A 标签')
导航到了 "A 标签"。我要如何重置 "B 标签",以便当用户再次导航到 "B 标签" 时,不再显示堆栈,而是显示 TabNavigator?
我尝试了以下方法:
navigation.reset({
index: 0,
routes: [{ name: 'B Tab' }],
});
这会移除堆栈,但会导航到 "B 标签" 屏幕,这不是我想要的。我希望留在当前屏幕。
英文:
I have a TabNavigator with two Tabs A Tab
and B Tab
.
In B
, there is a StackNavigator C Stack
. From within this stack, I navigate via navigation.navigate('A Tab')
to Tab A
. How can I reset B Tab
, that when the user navigates back to B Tab
, there is not the Stack, but the TabNavigator?
I tried
navigation.reset({
index: 0,
routes: [{name: 'B Tab'}],
});
This removes the tack, but this navigates to the sreen B Tab
which I do not want. I want to stay on current screen.
答案1
得分: 1
尝试这样做
import { CommonActions } from '@react-navigation/native';
navigation.dispatch(
CommonActions.reset({
index: 0,
routes: [
{ name: 'B Tab' }
],
})
);
英文:
try this
import { CommonActions } from '@react-navigation/native';
navigation.dispatch(
CommonActions.reset({
index: 0,
routes: [
{ name: 'B Tab' }
],
})
);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论