Reputation: 4557
Currently, as far as I know reset
in react-navigation
is done by dispatching a redux action of NavigationActions.reset();
Console logging this.props.navigation
shows a reset function, but if I try to use it as this.props.navigation.reset('Home')
, it throws me an error newStackActions.map
is not a function.
Can we reset the whole navigation without using redux? There should be such functionality, I guess I can't find it :/
Upvotes: 0
Views: 418
Reputation: 4557
So apparently, after trying out some methods. replace
seems to work just fine.
this.props.navigation.replace(ScreenName)
replaces your current screen to the specified screen without any increment to the screen stack, essentially you just switch screens over.
I'll just leave it here in case anyone needs help.
EDIT
Note - In case anyone is confused, replace
does not mimic the behaviour of a reset
function.
replace
just replaces your current active screen or the topmost screen on the stack with the given screen whereas
reset
essentially wipes off your whole navigation history and creates a new navigation object based on the screens references you provide. In other words you can essentially create a navigation stack full of screens you never visited. (not sure how it is possible ;))
Upvotes: 0
Reputation: 22209
You can make use StackActions to reset a particular stack, and dispatch it using navigation's internal dispatcher
import { StackActions, NavigationActions } from 'react-navigation';
const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'Profile' })],
});
this.props.navigation.dispatch(resetAction);
Upvotes: 1