user11587840
user11587840

Reputation:

How to keep a view on the screen last visited by the user in react-native?

Suppose I have three screens in my application.

Screen A, Screen B, Screen C

Now If the user exists or if the app crashes when the user is on Screen B, I want to redirect the user directly to Screen B when the user visits the application again.

I am using react-navigation for navigating between screens.

Should I store the every Screen name visited by the user in async storage and then read that value on app launch and redirect user according to that value or is there any simple and easy way?

Upvotes: 2

Views: 1600

Answers (1)

Gaurav Roy
Gaurav Roy

Reputation: 12235

First and foremost thing , like i've done it in my app , but there are few catches with it. If you want to redirect to that screen if the app crashes , then it's possible by the way you suggest , that keep the name of page in async storage and then redirect upon app start.

Things to keep in mind. 1. The page which you are redirecting to should not have props dependencies from any page prior to that. 2. If the app starts, then navigation stack is cleared. So in android if user clicks on back button and if you have used this.props.navigation.goBack() it may misbehave, so keep that in mind. A fix to this would be on back button press you can do this.props.navigation.navigate('Screen').

Ive did this in login , like im storing token ,and if user opens next time it doesnt show login page , but home page. so you can do it too. Just take care of above points.

Upvotes: 1

Related Questions