'How to clear navigation history in react-native
I created a login / signup page in my react-native app...I would like to prevent users from going back to that page after successful login
In nativescript, I do that by setting clearHistory: true when navigating
How can I do that in react-native
My navigation code is like this this.props.navigation.navigate('home screen', { email: email}
Thank you
Solution 1:[1]
If you're using react-navigation there is a method popToTop. This should clear your navigation stack, if 'home screen' isn't your app's first screen, you can navigate later:
this.props.navigation.popToTop();
this.props.navigation.navigate('home screen', { email: email};
Solution 2:[2]
In react navigation version 6
import { useNavigation, CommonActions } from '@react-navigation/native';
CommonActions.reset({
index: 1,
routes: [{ name: 'name of the screen that you wanna be in' }],
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kamil Owczarz |
| Solution 2 | Maruf Sharifi |
