Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
ReactJS: Redirect to homepage

I'm using react-router-dom, and I have a problem to redirect to the homepage (path="/").

Basically, I have a form with a submit button. When it is clicked I would to do the redirect.

const saveEntity = (event, errors, values) => {
    console.log('values .', values);
    if (values.realm) {
      setRealm(values.realm);
    }
    if (values.ente) {
      setEnte(values.ente);
    }
    if (values.realm) {
      console.log('dentro ', values.realm);
      // const history = useHistory();
      // const handler = () => {
      //   history.push('/');
      // };
      // return <Redirect to={{ pathname: '/' }} />;
    }
  };

return (
    <div>
      <AvForm  onSubmit={saveEntity}>
// .....

in the saveEntity I have tried to use history.push or Redirect, but nothing happens when I click the button.

How can I fix?

Thank you

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You don't need to use a handler, just history.push('/'). and you have to call useHistory() in the root of YourComponent as bellow

const YourComponnt = ()=>{
const history = useHistory();

const saveEntity = (event, errors, values) => {
    console.log('values .', values);
    if (values.realm) {
      setRealm(values.realm);
    }
    if (values.ente) {
      setEnte(values.ente);
    }
    if (values.realm) {
      console.log('dentro ', values.realm);
    }

   history.push('/'); // or history.replace('/');
  };

return (
    <div>
      <AvForm  onSubmit={saveEntity}>
// .....
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!