我正在用Expo构建一个React-Native应用程序。我尝试实现BottomTabNavigator,但是由于某种原因,内容(TripsPage)出现了两次。
这是我的导航实现:
<NavigationContainer>
<Stack.Navigator
initialRouteName="TripsPage"
screenOptions={{
headerStyle: {
backgroundColor: Colors.primary,
},
headerTintColor: 'black',
headerTitleAlign: 'center',
headerTitleStyle: {
fontWeight: 'bold',
fontSize: 18,
},
}}
>
<Stack.Screen
name="TripDetails"
component={TripDetails}
options={{ title: 'Trip Details' }}
/>
<Stack.Screen
name="TripsPage"
component={TripsPage}
options={{ title: 'Home' }}
/>
<Stack.Screen
name="MVPForm"
component={Form}
options={{ title: 'Trippy' }}
/>
<Stack.Screen
name="Result"
component={Result}
options={{ title: 'Car Allocation' }}
/>
</Stack.Navigator>
</NavigationContainer>
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen name="Home" component={TripsPage} />
</Tab.Navigator>
</NavigationContainer>
有人知道这个问题吗?
答案 0 :(得分:0)
您好,只尝试使用一个<NavigationContainer>
并将所有导航器包装在其中,如下所示:
<NavigationContainer>
<Stack.Navigator
initialRouteName="TripsPage"
screenOptions={{
headerStyle: {
backgroundColor: Colors.primary,
},
headerTintColor: 'black',
headerTitleAlign: 'center',
headerTitleStyle: {
fontWeight: 'bold',
fontSize: 18,
},
}}
>
<Stack.Screen
name="TripDetails"
component={TripDetails}
options={{ title: 'Trip Details' }}
/>
<Stack.Screen
name="TripsPage"
component={TripsPage}
options={{ title: 'Home' }}
/>
<Stack.Screen
name="MVPForm"
component={Form}
options={{ title: 'Trippy' }}
/>
<Stack.Screen
name="Result"
component={Result}
options={{ title: 'Car Allocation' }}
/>
</Stack.Navigator>
<Tab.Navigator>
<Tab.Screen name="Home" component={TripsPage} />
</Tab.Navigator>
</NavigationContainer>