react-native中导航库react-navigation
实现过程:
- 安装库
npm install --save react-navigation
index.ios.js
中代码示例12345678910111213141516171819202122232425262728293031323334import React from 'react';import {AppRegistry,View,Text,Button} from 'react-native';import { StackNavigator } from 'react-navigation'; // 引入import ChatScreen from './src/component/ChatScreen';class HomeScreen extends React.Component {static navigationOptions = {title: 'Welcome',};render() {const { navigate } = this.props.navigation;return (<View><Text>Hello, Navigation!</Text><ButtononPress={() => navigate('Chat')}title="Chat with Lucy"/></View>)}}const AwesomeProject = StackNavigator({Home: { screen: HomeScreen },Chat: { screen: ChatScreen },});AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);在根目录建文件夹
./src/component
,并创建文件ChatScreen.js
ChatScreen.js
代码示例:123456789101112131415161718import React, { Component } from 'react';import { Text, View} from 'react-native';export default class ChatScreen extends React.Component { static navigationOptions = { title: 'Chat with Lucy', }; render() { return ( <View> <Text>Chat with Lucy</Text> </View> ); }}
- 实现过程所遇问题:
index.ios.js
最后注册的是将导航栏AwesomeProject
,此处注册的不是HomeScreen