我想从stacknavigator内的一个组件注销,并且stacknavigator在bottomtabsnavigator内部,该标签最终位于包含两个switchnavigator的stacknavigator内部
我尝试过this.props.navigation.navigate(component)失败了,而其他几种方式让我有些困惑和沮丧,因为我是本机反应和导航的新手,所以将不胜感激
const AddContactTab = createStackNavigator({
AddContact: AddContactsActivity,
});
const ManageContactsTab = createStackNavigator({
ManageContacts: ManageContactsActivity,
viewContact: ViewSingleContactsActivity,
editContacts: EditContactsActivity
});
const Tabs = createBottomTabNavigator({
ManageContacts: ManageContactsTab,
AddContact: AddContactTab
}, {
tabBarOptions: {
activeBackgroundColor:'#3F51B5',
activeTintColor:'#ccc',
showLabel:false,
style: {
backgroundColor:'white',
color:'white'
},
tabStyle:{
},
// labelStyle:{
// color:'white',
// fontWeight: 'bolder',
// fontSize: 14
// }
},
defaultNavigationOptions: ({ navigation }) => ({
tabBarIcon: () => {
const { routeName } = navigation.state;
let tabName;
tabName = routeName === 'AddContact' ? 'plus' : 'home';
return <Icon name={tabName} size={24}
color="grey" />
}
})
},
);
export default createAppContainer(Tabs);
const MainStack = createStackNavigator(
{
Home: { screen: HomeActivity },
Register: {screen: RegistrationActivity}
},
{
initialRouteName: 'Home',
}
);
const AuthStack = createStackNavigator(
{
Dashboard: { screen: DashboardActivity },
},
{
initialRouteName: 'Dashboard',
}
);
const RootStack = createSwitchNavigator({
initialLoading: InitialLoadingActivity,
auth: AuthStack,
all: MainStack,
},
{
initialRouteName: 'initialLoading',
});
现在我想从addcontactsactivity注销到AuthStack堆栈导航器的初始路由。...如果我不太清楚,请告诉我,以便我可以编辑我的问题
答案 0 :(得分:0)
导航到该屏幕。
从“反应导航”导入{StackActions,NavigationActions};
const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'Profile' })],
});
this.props.navigation.dispatch(resetAction);
编辑:如果适合您,请使用它。
this.props.navigation.dispatch(
{
type: 'Navigation/NAVIGATE',
routeName: 'GoToANavigator',
action: {
type: 'Navigation/NAVIGATE',
routeName: 'GoToAScreenInANavigator',
}
}
);
答案 1 :(得分:0)
关于文档,我想您可以尝试:
this.props.navigation.dispatch(StackActions.popToTop())
popToTop操作将您带回到堆栈中的第一个屏幕,关闭所有其他屏幕。