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中的授权流示例,用于验证屏幕可视化逻辑: