NavigationActions.reset is not a function?
import { CommonActions,useNavigation } from '@react-navigation/native';
const navigation = useNavigation();
const resetAction = CommonActions.reset({
index: 0,
routes: [{ name: 'MainActivity' }],});
navigation.dispatch(resetAction);
document
If you're using react-navigation 5.0, you can do it this way
If you're using a nested router you'll also need to set key
to null otherwise it'll keep looking into currently active navigator.
import { NavigationActions, StackActions } from 'react-navigation'
const resetAction = StackActions.reset({
index: 0,
key: null, // <-- this
actions: [NavigationActions.navigate({ routeName: route })]
})
this.props.navigation.dispatch(resetAction)
Update for V5.x:
import { CommonActions } from '@react-navigation/native';
const resetAction = CommonActions.reset({
index: 1,
routes: [{ name: YOUR_ROUTE_NAME, params: { YOUR_OPTIONAL_DATA } }]
});
navigation.dispatch(resetAction);
in version >2 of react navigation, you can use this code to reset stack:
import { NavigationActions, StackActions } from 'react-navigation';
const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'MainActivity' })],
});
this.props.navigation.dispatch(resetAction);
I hope this will help...