我创建了以下代码以导入到app.js
import React from "react";
import { View } from "react-native";
import { createStackNavigator } from "react-navigation";
import HomeScreen from '../screens/HomeScreen';
import ProfileScreen from '../screens/auth/ProfileScreen';
import FilterScreen from '../screens/FilterScreen';
const Routes = createStackNavigator(
{
Home: {
screen: HomeScreen
},
Filters: {
screen: FilterScreen
},
Profile: {
screen: ProfileScreen
}
},
{
initialRouteName: "Home",
navigationOptions: {
headerTitleStyle: {
fontWeight: "bold",
color: "#fff",
},
headerTintColor: "#fff"
}
}
);
export default Routes;
我要按如下所示导入app.js
import Routes from './navigation/StackNavigator';
在此阶段预览我的应用程序时,出现以下错误:
undefined is not a function (near '...(0,
_reactNavigation.createStackNavigator)...')
<unknown>
C:\Apps\test\app\navigation\StackNavigator.js:9:6
loadModuleImplementation
C:\Apps\test\app\node_modules\metro\src\lib\polyfills\require.js:213:12
<unknown>
C:\Apps\test\app\App.js:7
loadModuleImplementation
C:\Apps\test\app\node_modules\metro\src\lib\polyfills\require.js:213:12
<unknown>
C:\Apps\test\app\node_modules\expo\AppEntry.js:2
loadModuleImplementation
C:\Apps\test\app\node_modules\metro\src\lib\polyfills\require.js:213:12
guardedLoadModule
C:\Apps\test\app\node_modules\metro\src\lib\polyfills\require.js:140:45
global code
<unknown file>:0
有人知道什么可能是错的吗?我正在撕头发!任何建议将不胜感激!
答案 0 :(得分:0)
建议:
Routes1
(在app.js
和navigation/StackNavigator
中)缩小错误范围,例如从createStackNavigator
中删除选项,然后尝试执行以下操作:
const Routes1 = createStackNavigator();
export default Routes1;
在此文件中尝试使用标签导航器(而不是stackNavigator),看看它是否可以正常工作。