如何解决反应原生导航:无法导航到堆栈中的顶部屏幕
我当前的导航是这样的
顶级堆栈
- 登录界面
- 主应用程序堆栈
- 主堆栈
- 搜索
- 设置选项卡堆栈
- 设置屏幕
我试图在设置屏幕中有一个退出按钮,按下后会导航到登录屏幕
目前它给出了一个错误 负载为 {"name":"Login"} 的操作“NAVIGATE”未被任何导航器处理。
退出按钮代码
<View style={{alignSelf: "center"}}>
<TouchableOpacity onPress={() => { navigation.navigate("Login") }}>
<Text>Sign Out</Text>
</TouchableOpacity>
</View>
这就是我的顶级堆栈的样子
<NavigationContainer>
<Stack.Navigator
initialRouteName="Login"
screenOptions={{
headerStyle: { backgroundColor: 'white',height: ScreenHeigth * 0 },headerTintColor: '#fff',}}>
<Stack.Screen name="Login" component={Login} options={{ title: '',headerLeft: null,gestureEnabled: false }}/>
<Stack.Screen name="Main" component={Main} options={{ title: '',gestureEnabled: false}} />
</Stack.Navigator>
</NavigationContainer>
解决方法
您是否尝试过 popToTop?
我在signOut视图
中更改了一些代码onPress按钮<View style={{ alignSelf: "center" }}>
<TouchableOpacity
onPress={() => {
navigation.popToTop();
}}
>
<Text>Sign Out</Text>
</TouchableOpacity>