在 React Navigation 中设置默认屏幕

问题描述 投票:0回答:1

我在代码中定义了“initialRouteName”,但它并不引用默认值,它正确地显示索引中的屏幕,并且实际上只有当我通过“登录”时才是它显示它的唯一方式, 也许我在这里错过了什么?

return (
    <NavigationContainer>
    <Stack.Navigator initialRouteName="Login" screenOptions={{ headerShown: false }}>
      <Stack.Screen name="Login" component={LoginScreen} />
      <Stack.Screen name="Index" component={Index} />
    </Stack.Navigator>
  </NavigationContainer>
        
  );

我下载了索引文件中的代码(该文件用作仪表板) 通过箭头功能直接从“登录屏幕”导航到“主屏幕”

const handleLogin = () => {
        console.log('Login with username and email');
        navigation.navigate('Home');
        
      };
    ```

The function will do anyway, but I tried to check if I have a problem with the index

And still the situation remains the same, he shows me the "Home screen" (only without dashboard)
react-native navigation react-navigation
1个回答
0
投票

尝试以下方法

import { createStackNavigator } from '@react-navigation/stack';

const Stack = createStackNavigator();

const MyStack = () => {
return (
<Stack.Navigator
  initialRouteName="Login">
<Stack.Screen name="Login" component={Login}/>
  <Stack.Screen name="Index" component={Index}/>
 </Stack.Navigator>
 );
 }

 const app = () =>{
 return (
 <NavigationContainer>
      <MyStack/>
 </NavigationContainer>
    
 );
© www.soinside.com 2019 - 2024. All rights reserved.