i want to return to the main screen of the device when i click in the back button, by default when i press the back button and im in the first screen it will go to the main screen but closing my app, i just to go to the main without closing it, im using BackHandler
, i have a tab navigator, do i need to add the listener to all of them? im just adding it in the first one, in this case Tracks:
componentDidMount() {
BackHandler.addEventListener("hardwareBackPress", this.hola);
}
componentWillUnmount() {
BackHandler.addEventListener("hardwareBackPress", this.hola);
}
hola = () => {
this.props?.navigation.goBack();
return true;
}
it throws me this error: The action 'GO_BACK' was not handled by any navigator.
and this is the structure of my navigator:
<Tab.Navigator>
<Tab.Screen name = "Tracks" children = {({navigation}) => <Tracks_List navigation = {navigation} tracks = {props.tracks}></Tracks_List>}></Tab.Screen>
<Tab.Screen name = "PlayList" children = {({navigation}) => <Play_List navigation = {navigation} tracks = {props.tracks}></Play_List>}></Tab.Screen>
<Tab.Screen name = "Artists" children = {() => <Stack_Navigator tracks = {props.tracks}></Stack_Navigator>}></Tab.Screen>
<Tab.Screen name = "Favorites" children = {({navigation}) => <Favorite_Songs navigation = {navigation} tracks = {props.tracks}></Favorite_Songs>}></Tab.Screen>
</Tab.Navigator>
want to go from here pressing the back button
to here without closing the app:
question from:
https://stackoverflow.com/questions/65600370/how-can-i-go-back-to-the-main-screen-of-the-device-with-navigation-react-native 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…