【发布时间】:2026-02-06 04:10:01
【问题描述】:
在尝试从 React-Navigation 实现导航器时,我遇到了一些奇怪的行为。
从https://reactnavigation.org/docs/en/hello-react-navigation.html尝试简单的“hello world”时...
import React from 'react';
import { View, Text } from 'react-native';
import { createStackNavigator } from 'react-navigation';
class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
</View>
);
}
}
export default createStackNavigator({
Home: {
screen: HomeScreen,
},
});
我收到此错误:
Invariant Violation:元素类型无效:期望字符串(对于内置组件)或类/函数(对于复合组件),但得到:对象。 检查'SceneView'的渲染方法。
奇怪的是,在使用 StackNavigator(和 TabNavigator)时,我会遇到 Invariant Violation,而使用 DrawerNavigator 却不会!
This common fix (removing the braces in the import) gives a new error:
对象不是函数
我是 React-Native 的新手,不知道如何深入研究这个问题,感谢任何帮助!
-----编辑-----
我已将我的 react-navigation 版本降级到 v1.5.5 并且原始 StackNavigator 组件可以正常工作,所以这可能是与 v2.0.1 和我的环境的兼容性问题。
【问题讨论】:
标签: react-native react-navigation