我是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 –