Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 使用嵌套导航器时initialRouteName工作不正常_React Native_React Navigation - Fatal编程技术网

React native 使用嵌套导航器时initialRouteName工作不正常

React native 使用嵌套导航器时initialRouteName工作不正常,react-native,react-navigation,React Native,React Navigation,我正在以以下方式组织我的应用程序: 堆栈导航器: 登录屏幕 注册屏幕 选项卡导航器 主屏幕 其他屏幕 但是,当我运行它时,第一个弹出的屏幕是主页,即使我设置了initialRouteName=“Login”。此外,单击“上一步”按钮将进入登录屏幕,但“上一步”按钮不再起作用 以下是相关代码: return ( <NavigationContainer> <Stack.Navigator initialRouteName=&

我正在以以下方式组织我的应用程序:

  • 堆栈导航器:
    • 登录屏幕
    • 注册屏幕
    • 选项卡导航器
      • 主屏幕
      • 其他屏幕
但是,当我运行它时,第一个弹出的屏幕是主页,即使我设置了
initialRouteName=“Login”
。此外,单击“上一步”按钮将进入登录屏幕,但“上一步”按钮不再起作用

以下是相关代码:

return (
        <NavigationContainer>
            <Stack.Navigator initialRouteName="Login">
                <Stack.Screen name="Login" component={telaLogin} options={{ headerStyle: {backgroundColor: '#766ec5', borderBottomWidth: 0, shadowColor: "transparent", elevation: 0,}, headerTitleStyle: {color: "#d9d9d9", }, headerTintColor: "#d9d9d9",}}/>
                <Stack.Screen name="Cadastro" component={telaCadastro} options={{headerStyle: {backgroundColor: "#766ec5", borderBottomWidth: 0, shadowColor: "transparent", elevation: 0,}, headerTitleStyle: {color: "#d9d9d9", }, headerTintColor: "#d9d9d9",}}/>
                <Stack.Screen name="Home" component={homeTabs} options={{ headerTitle: props => <LogoTitle {...props} />, headerTitleAlign: 'center', headerTintColor: "#d9d9d9", headerStyle: {backgroundColor: '#766ec5', borderBottomWidth: 0, shadowColor: "transparent", elevation: 0,}}}/>
            </Stack.Navigator>
        </NavigationContainer>
    )

function telaLogin({navigation}){
    return(
        <View style={styles.container}>
            <Image style={styles.logo1} source={logo} />
            <TextInput style={styles.txtinput} placeholder='Nome de usuário' placeholderTextColor='#d9d9d9' />
            <TextInput style={styles.txtinput} placeholder='Senha' placeholderTextColor='#d9d9d9' secureTextEntry = {true} />
            <TouchableOpacity style={styles.butao} onPress={navigation.navigate("Home")}> //this button specifically, it doesn't do anything
                <Text style={styles.txtbotao}> Entrar </Text>
            </TouchableOpacity>
             ...

function homeTabs({navigation}){
    return(
        <Tab.Navigator tabBarOptions={{showLabel: false, activeBackgroundColor: '#a5a7a7', inactiveBackgroundColor: '#d9d9d9', activeTintColor: '#766ec5',}} >
            <Tab.Screen name="Gerenciar Turmas" component={telaGerenciarTurmas} options={() => ({
                ...
            <Tab.Screen name="Preparação Para o Conselho" component={telaPrepConselho} options={() => ({
                ...
            <Tab.Screen name="Visualizar Estatísticas" component={telaVisualizarEstat} options={() => ({
                ...
        </Tab.Navigator>
    );
}
返回(
,headerTitleAlign:'center',HeaderTitColor:'d9d9d9',headerStyle:{backgroundColor:'766ec5',borderBottomWidth:0,shadowColor:'transparent',elevation:0,}}}/>
)
函数telaLogin({navigation}){
返回(
//特别是这个按钮,它什么都不做
诱捕者
...
函数homeTabs({navigation}){
返回(
({
...
({
...
({
...
);
}

您可以使用react navigation docs中的授权流示例,用于验证屏幕可视化逻辑: