Reader small image

You're reading from  React Router Quick Start Guide

Product typeBook
Published inSep 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781789532555
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Sagar Ganatra
Sagar Ganatra
author image
Sagar Ganatra

Sagar Ganatra is a frontend engineer and an architect from Bangalore, India. He has more than a decade of experience in developing web and mobile applications. He specializes in architecting projects using JavaScript and frameworks such as React, Angular, and Node. His previous books include Kendo UI Cookbook and Instant Kendo UI Mobile, both published by Packt Publishing. He also writes about frontend technologies in his blog, sagarganatra (dot) com.
Read more about Sagar Ganatra

Right arrow

The <Redirect> component

The <Redirect> component is included in the react-router-dom package. It helps in redirecting the user from the component where it's included to the route specified in the 'to' prop:

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

export class HomeComponent extends Component {
render() {
return (
<Redirect to='/dashboard' />
)
}
}

In the preceding scenario, when HomeComponent is rendered (based on a <Route> match), the user is redirected to the '/dashboard' route. For example, when the user accesses the home page (at path '/'), the <Route> with the path '/' renders the previous component and then the user is immediately redirected to the <Route> with its path value as '/dashboard'. This is similar to how a <Link...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
React Router Quick Start Guide
Published in: Sep 2018Publisher: PacktISBN-13: 9781789532555

Author (1)

author image
Sagar Ganatra

Sagar Ganatra is a frontend engineer and an architect from Bangalore, India. He has more than a decade of experience in developing web and mobile applications. He specializes in architecting projects using JavaScript and frameworks such as React, Angular, and Node. His previous books include Kendo UI Cookbook and Instant Kendo UI Mobile, both published by Packt Publishing. He also writes about frontend technologies in his blog, sagarganatra (dot) com.
Read more about Sagar Ganatra