我试图使用堆栈和选项卡导航器切换屏幕。

const MainNavigation = StackNavigator({
      otp: { screen: OTPlogin },
      otpverify: { screen: OTPverification},
      userVerified: {
        screen: TabNavigator({
          List: { screen: List },
          Settings: { screen: Settings }
        }),
      },
    });

在这种情况下,首先使用堆栈导航器,然后使用制表器。我想从堆栈导航器中隐藏头文件。这是不正常工作时,我使用导航选项::

navigationOptions: { header: { visible: false } }

我试图在前两个组件上使用这段代码在stacknavigator。 如果我使用这一行,然后得到一些错误,如:


当前回答

对我来说,navigationOptions不起作用。下面的方法对我很有效。

<Stack.Screen name="Login" component={Login}
      options={{
               headerShown: false
              }}
     />

其他回答

这招对我很管用:

const Routes = createStackNavigator({
Intro: {
    screen: Intro,
    navigationOptions: {
        header: null,
    }
}
},
    {
        initialRouteName: 'Intro',
    }
);

如果你使用反应导航版本:6。X可以这样用。在这里,SignInScreen头将隐藏下面的代码片段

options={{  
   headerShown: false,  
}} 

完整的脚本应该是

import {createStackNavigator} from '@react-navigation/stack';  
import SignInScreen from '../screens/SignInscreen';  
import SignUpScreen from '../screens/SignUpScreen';  
const Stack = createStackNavigator();    
function MyStack() {  
 return (   
   <Stack.Navigator>   
     <Stack.Screen   
       name="Sing In"  
       component={SignInScreen}  
       options={{  
         headerShown: false,  
       }}   
     />  
     <Stack.Screen name="Sing Up" component={SignUpScreen} />   
   </Stack.Navigator>   
 );    
}  
export default function LoginFlowNavigator() {    
 return <MyStack />;   
}

如果你想从整个屏幕中删除头部,去app.js并将这段代码添加到Stack中。导航器

screenOptions={ { headerShown: false } }

只需将此添加到您的类/组件代码片段和Header将被隐藏

 static navigationOptions = { header: null }

在你的目标屏幕上,你必须编写这样的代码!

 static navigationOptions = ({ navigation }) => {
    return {
       header: null
    }
 }