undefined 不是一个对象(评估'_reactNativeNavigation.default.push')

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

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

我收到一个错误:

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

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

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

或者可能是对堆栈的错误调用,因为我从不使用 App.js

中设置的 ID 属性

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

如果有人能指导我,我有点迷茫-_-

我的代码:

App.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"
                  }
                }
              }
            }
          }
        ]
      },

    }
  });
});

Landing.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;

jinshin1013RNN issue tracker 在 Landing.js,

我应该像这样导入导航:

import { Navigation } from 'react-native-navigation