reactjsreact-nativereact-native-navigationreact-navigation-v5

How to destroy current screen and navigate to another screen ? so that on back press that previous screen doesn't appear


Hello everyone i am new to react-native and stuck in a navigation problem. i have crawled through every question about this but found nothing helpful.

I have Navigation structure like this

Tab Navigator

  1. HomeStack [mainScreen,Screen2]

  2. PostStack[cameraScreen,UploadPostScreen]

Now i want to navigate to MainScreen of HomeStack after uploading the Post and along with that i want to remove these post and upload screen so that i can not go back by pressing back button.


Solution

  • You need to use replace method in that case, take a look here:

    https://reactnavigation.org/docs/stack-actions/#replace