I tried using
<Redirect to = 'loginPage' />
but it is not redirecting me anywhere. what should i do?
Please help me
I tried using
<Redirect to = 'loginPage' />
but it is not redirecting me anywhere. what should i do?
Please help me
You have two options to redirect:
Option 1:
Using <Redirect />
like in this example:
<Redirect
to={{
pathname: '/loginpage'
}}
/>
This option works most of the times except for component lifecycle methods, such as ComponentDidMount where you need to opt for the second option below.
Option 2:
Using this.props.history.push("/loginpage");
like in this example:
componentDidUpdate() {
if (this.props.authenticated === false) {
this.props.history.push("/loginpage");
}
}
Note that to use this option, the component must be a child component of <BrowserRouter />
. Otherwise, you have to use the withRouter()
HOC like in this example:
myComponent = withRouter(
ServicePlanSelect
);