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

202
Visualizações
The written link and condition is correct but the page does not move

I want my login page to go to the contact confirmation page if I get number 200 from the server, but it does not work. Where is my mistake?

 const [form, setForm] = useState({});

 async function checkLogin() {
     try {
         const response = await axios({
             url: 'https://api.bms-go2tr.com/api/v1/check',
             method: 'POST',
             data: form
         });

         if (response.status == 200) {
             return <Link to="/Verification"/>
         }
     } catch (error) {
         if (error.status == 493) {
             return <Link to="/Verification" />
         } else {
             alert(error.response.data.message)
         }
     }
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You cant return JSX like this in a callback and expect it to be rendered into the DOM. In callback handlers like this you are wanting to issue an imperative navigation action (i.e. using the navigate function), versus a declarative action (i.e. rendering a Link or Navigate component).

Use the useNavigate hook to access the navigate function and replace the Link with a call to navigate.

Example:

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

...

const navigate = useNavigate();
const [form, setForm] = useState({});

async function checkLogin() {
  try {
    const response = await axios({
      url: 'https://api.bms-go2tr.com/api/v1/check',
      method: 'POST',
      data: form
    });

    if (response.status == 200) {
      navigate("/Verification");
    }
  } catch (error) {
    if (error.status == 493) {
      navigate("/Verification");
    } else {
      alert(error.response.data.message);
    }
  }
}
about 4 years ago · Santiago Trujillo Relatório

0

<Link> Component is used to create link in your application but it don't navigate to that link. For Navigation you can use useNavigate() hook or <Navigate> Component(if you use react router v6).

Solution: Instead of <Link to="/Verification" /> use <Navigate to="/Verification" />.

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