Book Image

React Router Quick Start Guide

By : Sagar Ganatra
Book Image

React Router Quick Start Guide

By: Sagar Ganatra

Overview of this book

React Router is the routing library for React, and it can be used in both React Web and React Native applications. This book is a simple way to get started with React Router and harness its full power for your applications. The book starts with an introduction to React Router and teaches you how to create your first route using the React component. You will then learn about configuring your routes, passing parameters, and creating nested routes. You will be introduced to various components in React-Router and learn different configuration options available for these components. You will then see how to use the Redirect and Switch components. For even greater ?exibility, you will learn about BrowserRouter, HashRouter, NativeRouter, and StaticRouter. By the end of the book, you will have set up a project with React Router and make routing configuration work in a server-side rendered React application, a mobile application built with React Native and also understand how Redux and React-Router can be used in the same application.
Table of Contents (10 chapters)

Summary

The <Router> component in the react-router package provides a low-level implementation of the router interface. Various routers in react-router-dom and react-router-native use this low-level <Router> interface to provide routing features for the given environment. The history prop in <Router> is used to specify the history object for the given environment. For example, the <BrowserRouter> component uses history/createBrowserHistory to create a history object in the browser environment. All the Router components accept only one child, and it's usually the application's root component.

The BrowserRouter component in react-router-dom makes use of the HTML5 history API to keep the application's URL in sync with the browser's history. It accepts props—basename, keyLength, forceRefresh, and getUserConfirmation. The <HashRouter...