undefined 不是对象(评估‘routeconfigs initialroutename.params’)
2019-09-10
2750
我真的不明白我的代码中有什么问题,有人可以帮助我吗?
我的代码:
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;
1个回答
RouteNameOne
未在您的 stackNavigator 中定义
initialRouteName : 'RouteNameOne',
更改为
initialRouteName : 'Home',
Sunny Shah
2019-09-10