TypeError:未定义不是一个对象(正在评估'Object.keys(routeConfigs)')
2020-06-20
3212
import React from 'react';
import {createAppContainer} from 'react-navigation';
import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs';
import {createStackNavigator} from 'react-navigation-stack';
import { NavigationContainer } from '@react-navigation/native';
import Welcomepage from './Components/Rootstack/Welcomecomponent';
import Signpage from './Components/Rootstack/Signincomponent';
import Signuppage from './Components/Rootstack/SignupComponent';
import Whoyouare from './Components/Rootstack/selectfacstu';
import homescreen from './Components/Homestack/homescreen';
import ChatTab from './Components/Homestack/chatscreen';
import Blogpage from './Components/Rootstack/feedscreen';
import Settings from './Components/Homestack/settings';
import notifications from './Components/Homestack/Notification';
import profile from './Components/Homestack/profile';
import { Root } from "native-base";
const Stack = createStackNavigator();
function Rootstack() {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="welcome">
<Stack.Screen name="login" component={Signpage} />
<Stack.Screen name="signup" component={Signuppage} />
<Stack.Screen name="welcome" component={Welcomepage} />
<Stack.Screen name="who" component={Whoyouare} />
<Stack.Screen name="home" component={Homestack} />
</Stack.Navigator>
</NavigationContainer>
);
}
const Tab = createMaterialBottomTabNavigator();
function Homestack(){
return(
<Tab.Navigator
initialRouteName="Home"
activeColor="yellow"
barStyle={{ backgroundColor: '#0E043B' }}
>
<Tab.Screen
name="Home"
component={homescreen}
options={{
tabBarLabel: 'Home',
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="pentagon-outline" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Feed"
component={Blogpage}
options={{
tabBarLabel: 'Feed',
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="menu" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="write"
component={notifications}
options={{
tabBarLabel: 'bell',
tabBarIcon: ({ color }) => (
<FontAwesome5 name="bell" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="chat"
component={ChatTab}
options={{
tabBarLabel: 'chat',
tabBarIcon: ({ color }) => (
<MaterialIcons name="chat" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="profile"
component={profile}
options={{
tabBarLabel: 'Profile',
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="account" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="settings"
component={Settings}
options={{
tabBarLabel: 'settings',
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="settings" color={color} size={26} />
),
}}
/>
</Tab.Navigator>
);
}
export default class App extends Component {
render() {
return (
<Root>
<Rootstack />
</Root>
);
}
}
//below code is about installed dependency version
出现此错误,控制台/终端中没有错误,但是当我在 expo(Android)中运行它时,它会拒绝该错误,我也参考了 React 导航站点文档部分,并且我已经检查了所有可能的答案,但我无法修复此问题,并且我的一位开发人员朋友高效且成功地实现了相同类型的示例,我删除了该选项卡导航器部分并使用最少的示例进行了检查,但仍然出现相同的错误。
我该如何修复此问题?
2个回答
我通过更改 react navigation stack 的 import 语句解决了这个问题,该语句引用了无效/较旧的版本。 import {createStackNavigator} from ''@react-navigation/stack"; 是正确的
Yuva Raghav
2020-08-04
似乎
import { Root } from "native-base";
导致了问题。
下面是我已经实现并且运行良好的代码片段:
App.js:
import React from 'react';
import MainStackNavigator from './src/MainStackNavigator';
export default class App extends React.Component {
render() {
return <MainStackNavigator />;
}
}
MainStackNavigator.js
import * as React from 'react';
import {createStackNavigator} from '@react-navigation/stack';
import MainTabNavigator from './MainTabNavigator';
import CreateGame from './CreateGame';
import {NavigationContainer} from '@react-navigation/native';
const Stack = createStackNavigator();
function MainStackNavigator() {
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
initialRouteName="MainTabNavigator">
<Stack.Screen name="MainTabNavigator" component={MainTabNavigator} />
<Stack.Screen name="CreateGame" component={CreateGame} />
</Stack.Navigator>
</NavigationContainer>
);
}
export default MainStackNavigator;
MainTabNavigator.js
import React from 'react';
import {createMaterialBottomTabNavigator} from '@react-navigation/material-bottom-tabs';
import Icon from 'react-native-vector-icons/Ionicons';
import Home from './Home';
import Profile from './Profile';
import Dashboard from './Dashboard';
const Tab = createMaterialBottomTabNavigator();
export default function MainTabNavigator() {
return (
<Tab.Navigator
initialRouteName="Home"
//activeColor="#e91e63"
barStyle={{backgroundColor: '#ffffff'}}
labelStyle={{fontSize: 12}}>
<Tab.Screen
name="Home"
component={Home}
options={{
tabBarLabel: 'Home',
tabBarIcon: () => <Icon name="ios-home" color="#03C8A8" size={26} />,
}}
/>
<Tab.Screen
name="Dashboard"
component={Dashboard}
options={{
tabBarLabel: 'Dashboard',
tabBarIcon: () => (
<Icon name="stats-chart-sharp" color="#03C8A8" size={26} />
),
}}
/>
<Tab.Screen
name="Profile"
component={Profile}
options={{
tabBarLabel: 'Profile',
tabBarIcon: () => (
<Icon name="ios-person" color="#03C8A8" size={26} />
),
}}
/>
</Tab.Navigator>
);
}
Ankit Adlakha
2020-07-11