我需要在redux-action中导航。我试图从应用程序实现退出。我之前总是使用react-native-router-flux而不是非常熟悉react-navigation。
我的代码:
export const signOut = () => {
const nav = NavigationActions.navigate({
routeName: 'mainFlow', // It's navigation from drawer, so maybe I // don't need to specify this routeName?
action: NavigationActions.navigate({ routeName: 'intro' })
});
return () => {
try {
AsyncStorage.clear();
} finally {
AsyncStorage.getItem('token').then(function (response) {
console.log(response);
});
return nav;
}
}
};
Redux无法访问导航,但您可以做的是。例如,您的组件中有一个动作......
componentDidMount() {
this.props.getData();
}
并且此操作需要访问导航。你可以做的是,将导航传递给它。
this.props.getData(this.props.navigation);
例如,在getData操作中,您可以使用导航对象
const getData =(navigation) => {
navigation.navigate('ToYourScreen');
...
}