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

387
Views
How To Redirect To Another page in React js

I Want To redirect To List Page of My Application From App Component After Saving Data ... history.push("/List") not Working... Below Is my Code.. Please Help.

let history= useHistory();
 let SaveData=(props)=>{
 
    fetch('https://localhost:44345/api/Student/Save', {
      method: 'post',
      headers: {'Authorization': 'Basic ' + btoa('admin:admin'),'Content-Type':'application/json'},
      body: JSON.stringify({
       "Name": props.name,
       "Age": props.age,
       "Gender": props.gender
       
      })
     }).then(function(response) {
      console.log(response.status);       
      if (response.ok) {
        alert('Data Saved succesfully');
        redirect();
      }
  })
  }

  function redirect() {
    history.push("/List")
  }

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

0

You can use useNavigate from React-Router-Dom v6.

import { useNavigate } from "react-router-dom";

export default App() {
  const navigate = useNavigate()
  ...
  if (response.ok) {
    navigate('/list')
  }
}

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!