Reputation: 14831
I am building a React Native application. I am using React Navigation, https://reactnavigation.org/ for the navigation. Now, I am struggling the remove the current screen or history of the screen like in native Android.
I tried reseting it like below.
props.navigation.reset({
index: 0,
routes: [{ name: "ItemDetails" }]
})
I am invoking that code within the ItemList screen. But landed onto the ItemList screen from HomeScreen. If I use that code, the Home screen is also removed from the stack. But I only want to remove ItemList from the stack and maintain the Home screen. How can I do that?
Upvotes: 1
Views: 6994
Reputation: 296
EDIT: author specified that he wants to go to another page after removing current one from the stack.
Stack based navigators in react-navigation
have replace()
method, which will remove current screen from stack and go to arbitrary route (or "replace" current route) - https://reactnavigation.org/docs/stack-actions/#replace
If you want just to go back instead, goBack()
will remove current screen from stack and go to previous screen. https://reactnavigation.org/docs/navigation-actions/#goback
Upvotes: 5