【发布时间】:2020-03-26 14:23:57
【问题描述】:
我尝试创建一个名为 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 { 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(Navigator); 导出默认导航;
在 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',
},
})
错误说明:未定义不是对象(评估“OfferScreen.props.navigation”) 请帮我解决这个错误。我正在为导航而苦苦挣扎:(
【问题讨论】:
标签: reactjs react-native navigation native react-native-navigation