React Native导航

2020-04-21  本文已影响0人  南崽

点击进入官网

安装

配置

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'

堆栈导航

导入

import {NavigationContainer} from '@react-navigation/native';
//  导航容器
import {createStackNavigator} from '@react-navigation/stack';
//  导入创建堆栈导航方法

创建堆栈导航

const Stack = createStackNavigator();

创建导航需要的页面

包装到导航

 <NavigationContainer>
        <Stack.Navigator>
          <Stack.Screen 
            name="Home" 
            component={Home}
                />
          <Stack.Screen 
            name="Details" 
            component={Details}         
            />
        </Stack.Navigator>
      </NavigationContainer>
  • NavigationContainer 导航容器
  • Stack.Navigator 堆栈导航
  • Stack.Screen 堆栈导航页面

页面的跳转

this.props.navigation

参数的处理

navigation.push("Details",{id:"abc"})
this.props.route.params.id
<Stack.Screen   initialParams={{id:1}}></Stack.Screen>
上一篇 下一篇

猜你喜欢

热点阅读