【发布时间】:2023-04-02 06:22:01
【问题描述】:
我一直在尝试通过遵循本教程系列来学习 React Native,但我一直坚持使用 React Native 导航。 https://www.youtube.com/watch?v=5uIftiPLsC4&list=PLYxzS__5yYQlHANFLwcsSzt3elIbYTG1h&index=21
在 iPhone 模拟器上,我收到此错误:
(0, _reactNavigation.createStackNavigator) is not a function. (In '(0, _reactNavigation.createStackNavigator)({
home: App,
test: Test
})', '(0, _reactNavigation.createStackNavigator)' is undefined)
在 Android 上,我收到此错误:
Properties can only be defined on Objects.
这是我在 App.js 中的代码
import React, {Component} from 'react';
import {
Platform,
StyleSheet,
Text,
View,
Button
} from 'react-native';
import {createStackNavigator} from 'react-navigation';
class App extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
This is App component!
</Text>
<Button onPress={() => this.props.navigation.navigate('test')} title="Go to Test"></Button>
</View>
);
}
}
class Test extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
This is Test component!
</Text>
<Button onPress={() => this.props.navigation.navigate('home')} title="Go to App"></Button>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
export default createStackNavigator({
home: App,
test: Test
})
它基本上只是从教程中复制的,但我可以让它显示任何内容的唯一方法是如果我从底部删除以下内容
export default createStackNavigator({
home: App,
test: Test
})
并将导出默认添加回 App,但显然导航不起作用。
我已经安装了 react-navigation 和 react-native-gesture-handler(也已链接),并按照文档中的说明将这些行添加到了 android MainActivity.java。
我错过了什么吗?提前致谢。
【问题讨论】:
标签: javascript react-native react-native-navigation