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

In this chapter, we looked at how the <Link> and <NavLink> navigation components can be used to navigate to various routes defined in the application. These components render anchor links in the page, and, when the user clicks on these links, sections of the page are updated as opposed to doing a complete page reload, thus providing a lucid user experience. The <Link> component accepts the props to, replace, and innerRef.

The <NavLink> component is similar to the <Link> component, and it accepts all the props that the <Link> component works with. In addition to adding a link to the page, the <NavLink> component accepts several props—activeClassName, activeStyle, exact, strict, and isActive.

To create links to the nested routes, the <Link> and <NavLink> components can use the prefix match.url in the to prop....