在我的项目中,我有一个登录页面(位于stacknavigator中)和2个页面(位于createBottomTabNavigator中)。 createBottomTabNavigator包含在堆栈导航器中。我想从createBottomTabNavigator中的任何页面返回登录页面。对于导航,我使用“反应导航”:“ ^ 3.12.0”
导航堆栈代码:-
const RootStack = createStackNavigator({
Login:{
screen:LoginScreen
},
Home:{
screen:HometabNavigator
},
}, {
initialRouteName: 'Login',
headerMode: 'none'
});
const AppContainer = createAppContainer(RootStack);
屏幕中的代码:HometabNavigator:-
const TabStack = createBottomTabNavigator({
Dashboard: {
screen: Dashboard,
navigationOptions: () => ({
tabBarIcon: ({ tintColor }) => (
<Image
style={{
resizeMode: 'contain',
width: 18,
height: 18,
alignSelf: 'center',
marginLeft: 12,
marginRight: 12,
tintColor: tintColor
}}
source={IMAGEPATH.DASHBOARD_ICON_IMAGE}
/>
)
})
},
CoursePlan: {
screen: CoursePlan,
navigationOptions: ({ navigation }) => ({
tabBarIcon: ({ tintColor }) => (
<Image
style={{
resizeMode: 'contain',
width: 18,
height: 18,
alignSelf: 'center',
marginLeft: 12,
marginRight: 12,
tintColor: tintColor
}}
source={IMAGEPATH.COURSE_ICON_IMAGE}
/>
)
})
}
});
let TabNavigation = createAppContainer(TabStack);
class HometabNavigator extends React.Component {
<TabNavigation />
}
export default HometabNavigator;
现在,我正在尝试从CoursePlan导航到Login,并且代码如下:-
this.props.navigation.navigate('Login');
但是该页面未导航登录。我在这里做什么错了?
谢谢前进
答案 0 :(得分:0)
您的导航配置错误。容器不能包装回容器中
您需要修改导航配置。
const RootStack = createStackNavigator({
Login:{
screen:LoginScreen
},
Home:{
screen:TabStack
},
}, {
initialRouteName: 'Login',
headerMode: 'none'
});
const AppContainer = createAppContainer(RootStack);