How to clear navigation history in react-native

Viewed 5358

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

3 Answers

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};

This worked

navigation.replace('homescreen', {email : email})

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' }],       
    })

Related