【发布时间】:2019-05-25 08:39:36
【问题描述】:
在我的应用程序中,我使用 React-Navigation 设置了导航,没有像这样的导航道具:https://reactnavigation.org/docs/en/navigating-without-navigation-prop.html
但是,当我尝试拨打 NavigationService.navigate('LoginScreen');
从componentDidMount() 我得到'dispatch undefined'。
当我从render() 内部的onTap 调用相同的函数时,我按预期导航。
代码:
class SplashScreen extends Component {
componentDidMount() {
NavigationService.navigate('LoginScreen'); // does not work
}
//works at "onPress"
render() {
return (
<View style={styles.container}>
<Text onPress={() => NavigationService.navigate('LoginScreen')}>SplashScreen</Text>
</View>
);
}
}
关于如何解决这个问题的任何想法?
【问题讨论】:
标签: react-native react-native-navigation