我真的不明白我的代码中的问题是什么,有人可以帮我吗?
我的代码:
import React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
import {createStackNavigator} from 'react-navigation-stack';
import { createAppContainer } from 'react-navigation';
const MainNavigator = createStackNavigator({
Home: {screen: () => HomeScreen},
Profile: {screen: () => ProfileScreen},
},
{
initialRouteName : 'RouteNameOne',
}
);
const App = createAppContainer(MainNavigator);
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: 'Welcome',
};
render() {
const {navigate} = this.props.navigation;
return (
<Button
title="Go to Home"
onPress={() => navigate('Home', {name: 'Jane'})}
/>
);
}
}
export default App;
答案 0 :(得分:0)
RouteNameOne
未在您的stackNavigator中定义
initialRouteName : 'RouteNameOne',
更改为
initialRouteName : 'Home',