1.

How to redirect to another page in react js?

Answer»

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:

Example

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



Discussion

No Comment Found