React native 如何在redux操作中导航?
我需要在redux操作中导航。我正在尝试实现从应用程序退出。我以前总是使用react原生路由器流量,对react导航不太熟悉 我的代码:React native 如何在redux操作中导航?,react-native,react-navigation,React Native,React Navigation,我需要在redux操作中导航。我正在尝试实现从应用程序退出。我以前总是使用react原生路由器流量,对react导航不太熟悉 我的代码: export const signOut = () => { const nav = NavigationActions.navigate({ routeName: 'mainFlow', // It's navigation from drawer, so maybe I // don't need to specify th
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');
...
}
Redux无法访问导航,但您可以做的是。 例如,您的组件中有一个操作
componentDidMount() {
this.props.getData();
}
并且此操作需要访问导航。
您可以做的是,将导航传递给它
this.props.getData(this.props.navigation);
例如,在getData操作中,您可以只使用导航对象
const getData =(navigation) => {
navigation.navigate('ToYourScreen');
...
}