React Native - Router




React Native - Router

In this chapter, we will understand navigation in React Native.

Step 1: Install Router

To begin with, we need to install the Router. We will use the React Native Router Flux in this chapter. You can run the following command in terminal, from the project folder.

React Native - Router

Step 2: Entire Application

Since we want our router to handle the entire application, we will add it in index.ios.js. For Android, you can do the same in index.android.js.

App.js

React Native - Router

Step 3: Add Router

Now we will create the Routes component inside the components folder. It will return Router with several scenes. Each scene will need key, component and title. Router uses the key property to switch between scenes, component will be rendered on screen and the title will be shown in the navigation bar. We can also set the initial property to the scene that is to be rendered initially.

Routes.js

React Native - Router

Step 4: Create Components

We already have the Home component from previous chapters; now, we need to add the About component. We will add the goToAbout and the goToHome functions to switch between scenes.

Home.js

React Native - Router

About.js

React Native - Router

The app will render the initial Home screen

React Native - Router

You can press the button to switch to the about screen. The Back arrow will appear; you can use it to get back to the previous screen.

React Native - Router



Frequently Asked Questions

+
Ans: React Native - Debugging view more..
+
Ans: React Native - Animations view more..
+
Ans: React Native - Buttons view more..
+
Ans: React Native - Router view more..
+
Ans: React Native - Running IOS view more..
+
Ans: React Native - Running Android view more..
+
Ans: React Native - View view more..
+
Ans: React Native - WebView view more..
+
Ans: React Native - Modal view more..
+
Ans: React Native - ActivityIndicator view more..
+
Ans: React Native - Picker view more..
+
Ans: React Native - Text view more..
+
Ans: React Native - Alert view more..




Rating - NAN/5
548 views

Advertisements