首页 > 解决方案 > undefined 不是对象(评估 '_reactNativeNavigation.default.push')

问题描述

我刚刚将 RNN 更新到第 2 版,但我的第一次推送卡住了

我收到一个错误:

undefined is not an object (evaluating '_reactNativeNavigation.default.push') 

到目前为止,关于堆栈溢出的其他答案对我没有多大帮助

我想我的问题与此有关,this.props.componentId但我在官方文档中也找不到任何帮助。

或者它可能来自对堆栈的错误调用,因为我从不使用设置的 id 属性App.js

我还想知道是否必须为每个屏幕手动提供一个 id,或者正如文档中所说,它将由 RNN 自动完成

如果有人可以指导我,我有点迷路-_-

我的代码:

应用程序.js

import { Navigation } from 'react-native-navigation';
import { Provider } from 'react-redux';

import LandingScreen from './src/screens/Landing/Landing';
import AuthScreen from './src/screens/Auth/Auth';

import configureStore from './src/store/configureStore';

import strings from './src/global/strings';

const store = configureStore();

// Landing
Navigation.registerComponentWithRedux(strings.screens.screenLanding, () => LandingScreen, Provider, store);

// Auth
Navigation.registerComponentWithRedux(strings.screens.screenAuth, () => AuthScreen, Provider, store);


// Start App

Navigation.events().registerAppLaunchedListener(() => {
  Navigation.setRoot({
    root: {
      stack:{
        id:"appStack",
        children: [
          {
            component: {
              name: strings.screens.screenLanding,
              options: {
                topBar:{
                  title:{
                    text:"Welcome"
                  }
                }
              }
            }
          }
        ]
      },

    }
  });
});

登陆.js

import React, { Component } from 'react';
import { View, Button } from 'react-native';

import Navigation from 'react-native-navigation';

import strings from '../../global/strings';

class Landing extends Component {

    goToScreen = (screenName) => {
        Navigation.push(this.props.componentId, {
            component: {
                name: screenName
            }
        })
    }

    render() {
        return (
            <View>
                <Button
                    title="Connexion"
                    onPress={() => this.goToScreen(strings.screens.screenAuth.toString())}
                />
            </View>
        )
    }
}

export default Landing;

标签: react-nativereact-native-navigation

解决方案


RNN issue tracker In Landing.js中的jinshin1013所示,

我应该有这样的导入导航:

import { Navigation } from 'react-native-navigation

推荐阅读