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.
If you are only targeting iOS and would like to stick to the native look and feel, check out
Navigator component is older but has been thoroughly tested in production.
The community solution to navigation is a standalone library that allows developers to set up the screens of an app with just a few lines of code.
The first step is to install in your app:
Then you can quickly create an app with a home screen and a profile screen:
Each screen component can set navigation options such as the header title. It can use action creators on the
navigation prop to link to other screens:
React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside eachother, developers can override navigation logic for one area of the app without making widespread changes.
The views in React Navigation use native components and the
Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.
Like React Navigation,
Navigator can be adapted to render different components based on the current route in its
renderScene function. It will transition new scenes onto the screen by sliding in from the right by default, but you can control this behavior by using the
configureScene function. You can also configure a navigation bar through the
Check out the Navigator API reference for specific examples that cover each of these scenarios.
Like other navigation systems,
NavigatorIOS uses routes to represent screens, with some important differences. The actual component that will be rendered can be specified using the
component key in the route, and any props that should be passed to this component can be specified in
passProps. A "navigator" object is automatically passed as a prop to the component, allowing you to call
pop as needed.
NavigatorIOS leverages native UIKit navigation, it will automatically render a navigation bar with a back button and title.
Check out the
NavigatorIOS reference docs to learn more about this component.
You may also want to check out react-native-navigation, a component that aims to provide native navigation on both iOS and Android.
Since early 2016, React Native has shipped with an experimental re-implementation of the original
Navigator component called
CardStack. The major benefit it had over
Navigator is the smooth native-thread animations provided by the Animated library.
NavigationExperimental only included view components, it required a lot of boilerplate to use by itself. Several libraries sprung up around it, making it easier to use. Libraries such as
ex-navigation wrapped NavigationExperimental views in an easier-to-use API. Authors of many of these libraries now support React Navigation.
CardStack and other NavigationExperimental views live on as a part of the React Navigation project. The new library aims to be easy to use, while continuing to enable the smooth and customizable animations that NavigationExperimental pioneered.
As of React Native 0.43,
NavigationExperimental is deprecated. It will be removed from the codebase in a later version.
You can edit the content above on GitHub and send us a pull request!