React Native 正在从子导航容器返回父导航容器

a9wyjsp7  于 2023-02-13  发布在  React
关注(0)|答案(1)|浏览(122)

我的整个导航生命周期(说明):
App. js:路线(堆栈屏幕):启动画面、登录画面、注册画面、
optpscreen(组件网络=(子项)
Drawernavigation.js:
导航(抽屉式屏幕):主屏幕、注销屏幕(componenet =登录屏幕(在路线导航控制器中定义,用于注销后重置)
面临的问题:无法从导航(注销)导航到路线(登录屏幕)---需要重置
代码:-
App.js

const Stack = createNativeStackNavigator();

export function Route(){
  return(<>
  <NavigationContainer independent={true}>
      <Stack.Navigator initialRouteName='SplashScreen' screenOptions={{headerStyle:{
        backgroundColor:'#e6e6e6'
      }}}>

        
        {/* drawerScreen */}
        <Stack.Screen name="Nav" options={{ headerShown: false }} component={Nav} />
        
        {/* Navigation screens */}
        <Stack.Screen  options={{headerShown: false}}  name="SplashScreen" component={SplashScreen} />
        <Stack.Screen options={{headerShown: false}} name="LoginScreen" component={LoginScreen} />
        <Stack.Screen options={{title:''}} name="Otpscreen" component={Otpscreen} />
        <Stack.Screen options={{title:''}} name="Registerscreen" component={Registerscreen} />


      </Stack.Navigator>
    </NavigationContainer>
  </>)
}

function App(){
  
  return(<>
<Route />
  </>)
}

export default App;

DrawerNvigation.js

const Drawer = createDrawerNavigator();


const CustomDrawer = (props) => {
    return (<>
    
       <View>
       <View>
        <Image style={styles.Imagecss} source={require('../../assets/bq1.jpg')} />
       </View>
       <Text style={styles.BanquetNameCss}>Centeral Venue</Text>
       </View>
        <Text></Text>
        <DrawerItemList {...props} />
    
    </>)
}

return(
<>
    <StatusBar barStyle="dark" />
   
   
    <NavigationContainer independent={true}>

        <Drawer.Navigator drawerContent={(props)=><CustomDrawer {...props}/>} initialRouteName="Inquiries">

    <Drawer.Screen name="Inquiries" component={Mainscreen} 
        options={{
        drawerLabel:"Home"  ,
        drawerIcon: ({size}) => ( 
        <Icon name="home"  
        size={size} 
        color='black'
        /> ),
        }} />

<Drawer.Screen name="Sign Out" component={LoginScreen} 
        options={{
            drawerLabel:"Sign Out",
            drawerIcon: ({size}) => (
       
            <Icon name="sign-out"
        size={size}
        color='black'
        /> ) }}

> listeners={({navigation})=>{
> navigation.replace(<Route/>)
        }}

        />
   
        </Drawer.Navigator>
    
        </NavigationContainer>
    </>)
}

无法从孩子导航到父母,有没有人能帮助我让这个导航生命周期工作:)
我试着用这个逻辑

<Drawer.Screen name="Sign Out" component={LoginScreen}

登录代码:

function LoginScreen({navigation}){

    function preshandler(){
 navigation.navigate('Registerscreen');
    }

但它显示了有效载荷的错误,如图所示:Erorr

iszxjhcz

iszxjhcz1#

根据React Navigation Official Documentindependent在您的导航器中支持true表示断开任何父导航器
因此,这应该是您无法导航回父堆栈导航器的主要原因。
或者你有什么理由这么做?

相关问题