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

106
Views
Make redirection in express post, by react

I am using react and its router to make the redirect of my application. When I use a get instruction in my server express it works fine. But when I make a post instruction, it doesn't redirect. What I have to do?. Here is my code:

(I receive the response in the way that I expect, but after that, nothing happens)

lisaApp.post('/signup', (req, res) => {
  const validationResult = validateSignupForm(req.body);
  if (!validationResult.success) {
    return res.status(400).json({
      success: false,
      message: validationResult.message,
      errors: validationResult.errors
    });
  }

  var newClient = req.body
  newClient.clientemailname = newClient.userclient
  newClient.client_id = uuid.v4()

  delete newClient.confirmPassword

  ClientApi.saveClient(newClient, function (err, usr) {
    if (err) return res.status(500).send(err.message)

    console.log('ready to redirect') //Here, the response has a status "0k"
    res.redirect('/')
  });
});
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can write your api like this:

    lisaApp.post('/signup', (req, res) => {
      const validationResult = validateSignupForm(req.body);
      if (!validationResult.success) {
        return res.status(400).json({
          success: false,
          message: validationResult.message,
          errors: validationResult.errors
        });
      }

      var newClient = req.body
      newClient.clientemailname = newClient.userclient
      newClient.client_id = uuid.v4()

      delete newClient.confirmPassword

      ClientApi.saveClient(newClient, function (err, usr) {
        if (err) return res.status(500).send(err.message)

        console.log('ready to redirect') //Here, the response has a status "0k"
        return res.status(200).json({
            success:true,
            redirectUrl: '/'
        })
      });
    });

And in your React file you can use this code in your POST handler to redirect using react-router.

this.history.pushState(null, res.redirectUrl);

about 4 years ago · Santiago Trujillo 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!