我是本机反应的新手,但遇到了以下问题: (路由“主体”的组件必须是React组件。例如:...)。
我想将DrawerNavigator放在StackNavigator中。 我已经知道这是个好方法,但是它给了我我一直在寻找的错误,但我无法解决。
谢谢
App.js
import React, { Component } from 'react';
import {createAppContainer,createStackNavigator,createDrawerNavigator} from 'react-navigation';
import Login from './pantallas/login';
import Registro from './pantallas/registro';
import PantallaPrincipal from './pantallas/pantallaPrincipal';
import SolicitudCitas from './pantallas/socitudCitas';
import {Header,Icon} from 'native-base';
export default class App extends Component {
render() {
return <AppContainer/>;
}
}
const AppStackNavigator = createStackNavigator({
Login: { screen: Login },
Registro: { screen: Registro },
Principal: {screen: AppDrawerNavigator}
},{
headerMode: 'none',
navigationOptions: {
headerVisible: false,
}
}
);
const AppDrawerNavigator = createDrawerNavigator({
PantallaPrincipal:{screen: PantallaPrincipal},
SolicitudCitas: {screen: SolicitudCitas}}
,{
defaultNavigationOptions: ({ navigation }) => {
return {
headerLeft: (
<Header>
<Icon
style={{ paddingLeft: 10 }}
onPress={() => navigation.openDrawer()}
name="menu"
size={30}/>
</Header>
)
};
}
}
);
const AppContainer = createAppContainer(AppStackNavigator);
pantallaPrincipal.js
import React, { Component } from 'react';
import { Text, View,StyleSheet } from 'react-native';
export default class pantallaPrincipal extends Component {
render() {
return (
<View style={styles.backgroundContainer}>
<Text>Pantalla principal</Text>
</View>
);
}
}
const styles = StyleSheet.create({
backgroundContainer : {
flex: 1,
width: null,
height: null,
justifyContent: 'center',
alignItems: 'center'
}
});
solicitudCitas.js
import React, { Component } from 'react';
import { Text, View } from 'react-native';
export default class solicitudCitas extends Component {
render() {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>Solicitud Citas</Text>
</View>
);
}
}
答案 0 :(得分:0)
只需在要使用它的Stack导航器上方声明并初始化DrawerNavigator。这只是由于提升JS基础而发生的。在javascript中,只悬挂声明而不初始化,因此,当您使用Principal: {screen: AppDrawerNavigator}
时,JS不知道AppDrawerNavigator
实际上是一个React组件,因为它在使用前没有被初始化。您可以在JS here中学习有关提升的更多信息。
希望这会有所帮助。祝您编码愉快!