Following are several ways:
Using the component
import React from 'react'
import { Redirect } from 'react-router-dom'
const ProtectedComponent = () => {
if (authFails)
return <Redirect to='/login' />
}
return <div> My Protected Component </div>
}
Within a function
myFunction() {
addSomeStuff()
this.props.history.push('/path')
}
On click event on an element
<div onClick={this.props.history.push('/path')}> some stuff </div>
or
<Link to='/path' > some stuff </Link>
Comments
Post a Comment