Search code examples
react-nativereact-native-navigationmobile-developmentreact-native-navigation-v2

How to jump from one screen to another and clear all other screen from stack in ReactNative?


I have an application where I have a tab screen and few screens. From tab I navigate in order screen 1 -> screen 2 -> screen 3 . From screen 3's button click, I want to open screen - 4 i.e listing screen and on backpress I want to navigate agin tab screen.

I dont want to reset full stack using props.navigation.reset({index: 0,routes: [{name: "home"}],});, also number of navigating screen between tab screen and screen 4 is not fixed so I can't use props.navigation.pop(3) also.

Can anyone guide me, how to achieve this?

Thanks in advance


Solution

  • I found a way to achieve above navigation.

    props.navigation.popToTop();
    

    This will remove all screen from stack except main screen. Hope this helps others!!