Reactjs 导航选项中react native中两个屏幕之间的导航
我试图为导航创建一个名为Navigate.js的特殊屏幕。这是我写的:Reactjs 导航选项中react native中两个屏幕之间的导航,reactjs,react-native,navigation,native,react-native-navigation,Reactjs,React Native,Navigation,Native,React Native Navigation,我试图为导航创建一个名为Navigate.js的特殊屏幕。这是我写的: /** * Navigate.js * * Root component of the app, * responsible for setting up routes. * */ // Libs import React from 'react'; import { View, Text, Button } from 'react-native'; import { createAppCo
/**
* Navigate.js
*
* Root component of the app,
* responsible for setting up routes.
*
*/
// Libs
import React from 'react';
import { View, Text, Button } from 'react-native';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
// Components
import OfferScreen from './screens/OffersScreen';
import Post from './screens/Post';
/**
* createStackNavigator
*
* Creates a stack of our routes.
*
*/
const Navigator = createStackNavigator({
OfferScreen: { screen: OfferScreen },
Post: { screen: Post },
});
/**
* createAppContainer
*
* Responsible for managing app state and linking
* the top-level navigator to the app environment.
*
*/
const Nav=createAppContainer(导航器);
导出默认导航
在OfferScreen中,我有以下代码:
static navigationOptions =({}) =>({
title: "Oferte",
headerTitleStyle: { alignSelf: 'center', },
headerStyle: {
backgroundColor: '#BA272A',
},
headerRight: (
<View style={{paddingRight:11}}>
<Button
color="#ff5c5c" title="Tombola"
onPress={() =>
this.props.navigation( 'Post' )}
/>
</View>
),
headerTintColor: 'white',
headerTitleStyle: {
fontWeight: 'bold',
},
})
静态导航选项=({})=>({
标题:“奥弗特”,
headerTitleStyle:{alignSelf:'center',},
头型:{
背景颜色:“#BA272A”,
},
头灯:(
this.props.navigation('Post')}
/>
),
头部颜色:“白色”,
头饰样式:{
fontWeight:'粗体',
},
})
错误说明:undefined不是对象(评估'OfferScreen.props.navigation')
请帮我纠正这个错误。我正在为导航而挣扎:(您将导航对象交付给
导航选项。
然后使用导航。按或导航。导航移动屏幕
每次调用push
时,我们都会向导航
堆栈添加一条新路线。
当您调用navigate
时,它首先尝试使用
该名称,并且仅当网络上还没有新路由时才推送新路由
堆叠
静态导航选项=({navigation})=>{
标题:“奥弗特”,
headerTitleStyle:{alignSelf:'center',},
头型:{
背景颜色:“#BA272A”,
},
头灯:(
navigation.push('Post')}
/>
),
头部颜色:“白色”,
头饰样式:{
fontWeight:'粗体',
},
})
示例
从“React”导入React;
从“react native”导入{按钮、视图、文本};
从“反应导航”导入{createStackNavigator,createAppContainer};//可以在package.json中指定版本
类主屏幕扩展了React.Component{
静态导航选项=({navigation})=>({
标题:“奥弗特”,
headerTitleStyle:{alignSelf:'center',},
头型:{
背景颜色:“#BA272A”,
},
头灯:(
navigation.push('Details')}
/>
),
头部颜色:“白色”,
})
render(){
返回(
主屏幕
this.props.navigation.navigate('Details')}
/>
);
}
}
类DetailsScreen扩展了React.Component{
render(){
返回(
详细信息屏幕
);
}
}
const RootStack=createStackNavigator(
{
主页:主屏幕,
详情:详情屏幕,
},
{
initialRouteName:“主页”,
}
);
const-AppContainer=createAppContainer(RootStack);
导出默认类App扩展React.Component{
render(){
返回;
}
}
仍然不起作用。我用力推了推。这次没有错误。但巴顿什么也没做。@AdelinBojan我给你举了个例子。看看我的答案。