react-native - 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;
解决方案
如RNN issue tracker In Landing.js中的jinshin1013所示,
我应该有这样的导入导航:
import { Navigation } from 'react-native-navigation
推荐阅读
- java - selenium - 截屏时“接收来自渲染器的消息超时:10.000”
- reactjs - ReactJS 错误 - 实现绝对导入后“TypeError: Object(...) is not a function”
- typo3 - 需要清理 TYPO3 存储库功能中的用户输入吗?
- swift - 将 Text() 添加到 VStack 时,SwiftUI“调用中位置 #11、#12 的额外参数”
- javascript - 数据不会传输到 Angular 组件
- vba - Excel VBA将索引公式分配给变量
- php - 在对象中搜索元键并获取值
- amazon-web-services - EKS Kubernetes 出站流量
- html - 如何在输入字段顶部放置加号
- javascript - 创建集合 javascript