Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
948 views
in Technique[技术] by (71.8m points)

javascript - How can I go back to the main screen of the device with navigation? REACT-NATIVE NAVIGATION V5

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

enter image description here

to here without closing the app:

enter image description here

question from:https://stackoverflow.com/questions/65600370/how-can-i-go-back-to-the-main-screen-of-the-device-with-navigation-react-native

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...