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

391
Visualizações
How to dynamically change URL in a Next.js application without using <Link>?

I know it's possible to dynamically change the URL without refreshing the page by using <Link>; however, is it possible to do so without <Link>? For context, I'm trying to change the URL dynamically on a page to another one if a variable changes its value from false to true. The variable's value isn't dependent on a button being clicked on, so that's why I don't want to use <Link>. At the moment, I'm using window.top.location.href inside of a useEffect(), which gets the job done — but it's very clunky since the entire page reloads. Does anyone know how to achieve what I'm trying to do?

The following is what I'm currently doing:

useEffect(() => {
  if (status === true) {
    window.top.location.href='https://www.website.com'
  };
}, [status];
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I figured out a solution. All I needed to do was swap out the line with window.top.location.href to router.push(). The following is the updated code that works as intended:

useEffect(() => {
  if (status === true) {
    router.push('https://www.website.com')
  };
}, [status];
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