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

149
Visualizações
Best way to restrict page access?

I'm designing a website with a form component that redirects to a "failure" or "success" component based on whether the form submits without an error or not. Here is the code I'm using:

await axios
  .post('/api/patients/', data, axiosConfig)
  .then((response) => {
    history.push('/success');
  })
  .catch((error) => {
    history.push('/failure');
  });

This works well even when I intentionally make a bad request by turning my network off or changing the route. However, I can type in the "/success" route in my browser and access it whether or not I've submitted the form. How do I restrict this behavior?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm not sure if it is possible to track that the route was entered manually, but you can pass to the "success" component props like "submit: true", and render component if this props exist.

await axios
.post('/api/patients/', data, axiosConfig)
    .then((response) => {
        history.push({
          pathname: '/success',
          state: { submit: true }
        });
 })
 .catch((error) => {
   history.push({
     pathname: '/failure',
     state: { submit: true }
   });
 });

And in "success" component check props like:

if (props.location.state.submit) { . . . }
about 4 years ago · Juan Pablo Isaza 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