我是React native的新手,尝试跟随教程学习,但无法获得屏幕之间的导航工作。我以前使用一个屏幕就可以正常工作,但是当添加导航时,我会收到错误。React本地导航 - 未定义不是对象
在此之后:https://facebook.github.io/react-native/releases/next/docs/navigation.html
给了我这样的代码:
import React from 'react';
import {
StackNavigator,
} from 'react-navigation';
export default class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Welcome',
};
render() {
const { navigate } = this.props.navigation;
return (
<Button
title="Go to Jane's profile"
onPress={() =>
navigate('Profile', { name: 'Jane' })
}
/>
);
}
}
class ProfileScreen extends React.Component {
static navigationOptions = {
title: 'Profile',
};
render() {
return (
<Button title="do nothing"/>
);
}
}
const App = StackNavigator({
Home: { screen: HomeScreen },
Profile: { screen: ProfileScreen },
});
试图在错误
未定义运行这个(通过世博会的应用程序)的结果不是一个对象(评估'this.props.navigation.navigate')
所以我正在做导航,我该如何解决这个错误?
如果是U渲染'' –
Ricky
你能展现您调用的index.ios.js文件 'AppRegistry.registerComponent('MyAwesomeApp',()=> App);' – Dpkstr
您的HomeScreen组件中是否有构造函数?也许你无法访问道具。阅读:https://facebook.github.io/react/docs/react-component.html#constructor –