The best way to redirect a page in React.js depends on what is your use case. Let us get a bit in detail:

If you want to protect your route from unauthorized access, use the component and try this:

BY Best Interview Question ON 30 Jun 2020


import React from 'react'
import { Redirect } from 'react-router-dom'
const ProtectedComponent = () => {
   if (authFails)
   return <Redirect to='/login' />
return <div> My Protected Component </div>