我正在使用React native来为iOS和Android开发多页面应用程序。
我已经使用React Navigation从一页导航到另一页。但是不知何故它不起作用并给出错误消息。
这是我到目前为止所做的。
App.js
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
import { StackNavigator } from 'react-navigation';
import Settings from './Settings';
import Home from './Home';
const AppNavigator = StackNavigator({
SettingScreen: { screen: Settings },
HomeScreen: { screen: Home }
});
export default class App extends Component {
render() {
return (
<AppNavigator />
);
}
}
Home.js
import React, { Component } from 'react';
import { View, Text } from 'react-native';
export class Home extends Component {
render() {
return (
<View>
<Text>This is the home screen</Text>
</View>
)
}
}
export default Home
Settings.js
import React, { Component } from 'react';
import { View, Text, Button } from 'react-native';
export class Settings extends Component {
render() {
return (
<View>
<Text>This is the Settings screen</Text>
<Button onPress={() => this.props.navigation.navigate('HomeScreen')} title="Home"/>
</View>
)
}
};
export default Settings;
这是我收到错误消息的方式:
我们将不胜感激任何帮助或提示。
注意:
答案 0 :(得分:1)
对于版本3的反应导航,您可以这样配置路由器:
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
import { createStackNavigator, createAppContainer } from 'react-navigation';
import Settings from './Settings';
import Home from './Home';
const AppNavigator = createStackNavigator({
SettingScreen: { screen: Settings },
HomeScreen: { screen: Home }
});
export default createAppContainer(AppNavigator);
您还可以阅读文档here 希望对您有所帮助。