将导航启动屏幕更改为登录屏幕

时间:2018-11-02 06:06:52

标签: react-native react-navigation

我创建了一个初始屏幕和一个登录屏幕。我希望两秒钟后我的屏幕闪屏登录,但显示:undefined is not an object(evaluating '_this.props.navigation.push ')

在这个项目中,我正在使用反应导航

componentWillMount(){
setTimeout(
    () => {
        this.props.navigation.push({
            screen:'smartbill.login',
            title:'LOGIN SCREEN'
        });
    }
, 1000);

}

2 个答案:

答案 0 :(得分:1)

希望您已经创建了一个堆栈导航器

 const App = createStackNavigator({
  Splash: { screen: SplashScreen },
  Login: { screen: LoginScreen },
});

在启动画面中

setTimeout(()=> {
   navigate('Login', { name: 'Jane' })
 },1000);

答案 1 :(得分:0)

下面是我从启动画面导航到主屏幕的示例

 setTimeout(
            ()=> {
              this.props.navigation.navigate("Home");
                },1000
        );

对于导航,您应该在本机方法中使用StackNavigator,这是正确的方法

您从哪里得到的this.props.navigation.push 不正确

我在以下问题中有一个例外答案

How to navigate from splash screen to login screen in react native?

上面有一个google驱动器链接,您可以从中下载示例项目,其简单的app可以从示例应用程序中了解如何设置App.js

我建议您为StackNavigator使用 navigation,因为它是{{1}配置app中的最佳方法}}。

相关问题