我正在使用React-Native和Firebase Social App进行登录时出现错误:不变违规:在配置导航器时,请至少指定一条路线。不变
我想我在createStackNavigator,createDrawerNavigator和createAppContainer中确实输入了错误
实际上我不知道
const PostStack = createStackNavigator({
Post:{
screen: Post,
navigationOptions: navOptionHandler
},
PostEdit:{
screen:PostEdit,
navigationOptions:navOptionHandler
}
})
const FeedStack = createStackNavigator({
Feed:{
screen:Feed,
navigationOptions: navOptionHandler
},
FeedDetail: {
screen:FeedDetail,
navigationOptions: navOptionHandler
},
});
const NewsStack = createStackNavigator({
News:{
screen:News,
navigationOptions: navOptionHandler
},
NewsDetail: {
screen:NewsDetail,
navigationOptions: navOptionHandler
}
})
const AuthStack = createStackNavigator({
Login:{
screen: Login,
navigationOptions:navOptionHandler
},
Register:{
screen:Register,
navigationOptions:navOptionHandler
}
})
const MainTabs = createStackNavigator(
{
default: createBottomTabNavigator(
{
Feed: {
screen: Feed,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name="ios-home" size={24} color={tintColor} />
)
}
},
Post: {
screen: Post,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon
name="ios-add-circle"
size={48}
color="#1C5DDE"
style={{
shadowColor: "#ff787f",
shadowOffset: { width: 0, height: 0 },
shadowRadius: 10,
shadowOpacity: 0.3
}}
/>
)
}
},
News: {
screen: News,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name="ios-person" size={24} color={tintColor} />
)
}
}
},
{
defaultNavigationOptions: {
tabBarOnPress: ({ navigation, defaultHandler }) => {
if (navigation.state.key === "Post") {
navigation.navigate("postModal");
} else {
defaultHandler();
}
}
},
tabBarOptions: {
activeTintColor: "#161F3D",
inactiveTintColor: "#B8BBC4",
showLabel: false
}
}
),
postModal: {
screen: Post
}
},
{
mode: "modal",
headerMode: "none"
}
);
const MainStack = createStackNavigator({
Auth: {
screen:AuthStack,
navigationOptions: navOptionHandler
},
Home: {
screen: MainTabs,
navigationOptions: navOptionHandler
},
Contact: {
screen: Contact,
navigationOptions: navOptionHandler
},
About: {
screen: About,
navigationOptions: navOptionHandler
}
},{initialRouteParams:'Loading'})
const MainApp = createDrawerNavigator((createSwitchNavigator),
{
auth:AuthStack,
drawer:MainStack
},
{
contentComponent: SideMenu,
drawerWidth: Dimensions.get('window').width *7/10
},
{initialRouteParams:'auth'}
)
const AppNavigator = createAppContainer(MainApp);
export default class App extends React.Component {
render(){
return(
<AppNavigator/>
)
}
}
更改
const MainApp = createDrawerNavigator((createSwitchNavigator),
{
auth:AuthStack,
drawer:MainStack
},
{
contentComponent: SideMenu,
drawerWidth: Dimensions.get('window').width *7/10
},
{initialRouteParams:'auth'}
)
to
const MainApp = createDrawerNavigator(
{
auth:AuthStack,
drawer:MainStack
},
{
contentComponent: SideMenu,
drawerWidth: Dimensions.get('window').width *7/10
},
{initialRouteParams:'auth'}
)
希望这会有所帮助!