Answer the question
In order to leave comments, you need to log in
How to cancel the redirect to the main page?
It is necessary that after submitting the form, if the function responds negatively, no redirect occurs, and if it is positive, it does. By default, a redirect always occurs. How can this be implemented?
Answer the question
In order to leave comments, you need to log in
import { Redirect } from "react-router-dom"
......
state = { shouldRedirect: false, error: null }
onSubmit = () => {
const response = /* ..... true | false */
this.setState({
shouldRedirect: response,
error: response ? null : 'Something wrong!'
})
}
render() {
if (this.state.shouldRedirect) return <Redirect to="/" />
return (
{ this.state.error && <div className="error">{this.state.error}</div> }
.......
)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question