This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android.
If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following library provides native navigation on both platforms: react-native-navigation.
Install the react-navigation
package in your React Native project.
Install react-native-gesture-handler
and react-navigation-stack
Moving between screens
getParam
- get a specific param with fallback.
goBack
- close active screen and move back in the stack.
The following code snippet demostrates the situation.
We make use of BackHandler
which comes with react-native and
we subscribe to navigation lifecycle updates to add our custom hardwareBackPress listener.
navigationOptions
with setParams
You can read the full list of available navigationOptions
for screens
inside of a stack navigator in the createStackNavigator
reference.
StackNavigatorConfig
initialRouteName
- Sets the default screen of the stack. Must match one of the keys in route configs.headerMode
- No header will be rendered.gesturesEnabled
- Whether you can use gestures to dismiss this screen. Defaults to true on iOS, false on Android.transitionConfig
- Function to return an object that is merged with the default screen transitions.Example transitionConfig
: View on Github react-navigation-transitions
View code Navigating Between Screens App.js
This guide covers createBottomTabNavigator. You may also use createMaterialBottomTabNavigator and createMaterialTopTabNavigator to add tabs to your application.
createBottomTabNavigator
createMaterialBottomTabNavigator
createMaterialTopTabNavigator