Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda