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

134
Visualizações
redirect to same component under different conditions?

I am trying to redirect to same component but under diffract conditions and i am using windows.location.pathname as a way to know when the user is hitting the second endpoint my question is there a way to know the current location ? I tried to use context but it wont work because I don't want the context provider to give state to the main page that I am redirecting from also could my approach be considered bad ?

  <Route path='/creator' exact component={maincomponent} />
  <Route path='/viewer' exact component={maincomponent} />

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

0

If you want to learn the current path, you can use useLocation from react-router-dom.

For example:

import { useLocation } from 'react-router-dom'

function PathView() {
  const location = useLocation();
  const currentPath = location.pathname

  return <span>{currentPath}</span>
}

But if you want to use Routes with if condition, you can simply use {}.

For example:

{"YOUR_VARIABLE" === "YOUR_VARIABLE" ? (
  <Route path='/creator' exact component={maincomponent} />
) : (
  <Route path='/viewer' exact component={maincomponent} />
)
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