Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
React Router Quick Start Guide

You're reading from   React Router Quick Start Guide Routing in React applications made easy

Arrow left icon
Product type Paperback
Published in Sep 2018
Publisher Packt
ISBN-13 9781789532555
Length 156 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Sagar Ganatra Sagar Ganatra
Author Profile Icon Sagar Ganatra
Sagar Ganatra
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Introduction to React Router 4 and Creating Your First Route FREE CHAPTER 2. Configuring Routes - Using Various Options in the Route Component 3. Using the Link and NavLink Components to Navigate to a Route 4. Using the Redirect and Switch Components 5. Understanding the Core Router, and Configuring the BrowserRouter and HashRouter components 6. Using StaticRouter in a Server-Side Rendered React Application 7. Using NativeRouter in a React Native Application 8. Redux Bindings with connected-react-router 9. Other Books You May Enjoy

Adding <StaticRouter> and creating routes

The <StaticRouter> component is part of the react-router-dom package (uses <StaticRouter> definition in react-router), and it's used in rendering React-Router components on the server-side. The <StaticRouter> component is similar to the other Router components, as it accepts only one child component—the React application's root component (<App />). This component should be used in a stateless application, where the user is not clicking around to navigate to different sections of the page.

Let's include the <StaticRouter> component by wrapping the application's root component:

import { StaticRouter } from 'react-router-dom';

app.get('*', (req, res) => {
const context = {};
const reactMarkup = ReactDOMServer.renderToString(
<StaticRouter...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime