Ananth Sridhar
Ananth Sridhar

Reputation: 13

App Navigation state persisting EVEN IF app closed and restarted

I have a react-native app with two screens, Home and Details. Using react-navigation, Ive set the Stack navigator as following

const RootStack = createStackNavigator(
{
 Home: FormComponent,
 Details: DetailScreen
},
{
 initialRouteName: "Home",
 headerMode: "none"
}
);

Home contains a form, which once submitted, navigates to the Details screen with relevant data (using navigation.navigate("Details",{some data})). At this point, if I exit the app, and then open it again, the Details screen loads, with all the data preserved(Instead of the Home screen). I logged the navigation object data (this.props.navigation.) and it prints like the app was never closed.
Am I missing something here? Im new to React Native and Navigation, but from what I understand this is not expected behaviour.

Tried uninstalling app and rebuilding. This resets the app and Home screen loads. If I try reinstalling without uninstalling, back to same behaviour. Tried also manually forcing navigation.goBack() on ComponentWillUnmount() but no difference.

Upvotes: 1

Views: 2462

Answers (1)

cltsang
cltsang

Reputation: 1829

This should've been a comment but sadly i don't have enough reputation. Could you check if you haven't accidentally set a persistenceKey as a navigator prop?

https://reactnavigation.org/docs/en/state-persistence.html

Upvotes: 1

Related Questions