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

167
Visualizações
nextjs trying to pass current url to share on social media

I've created a helper function to generate urls for me like this

  function generateUrl(platform: string) {
  const currentUrl = typeof window !== 'undefined' ? window.location.href : ''
  switch (platform) {
    case 'facebook':
      return `https://www.facebook.com/sharer/sharer.php?u=${currentUrl}`
    default:
      return ''
  }
}

When I console log this its all working fine and I get the expected result, when I bundle this up into an Link/a tag within the app, it returns just the url without currentUrl so it just sends me to https://www.facebook.com/sharer/sharer.php?u= without url at the end ? Could it be cause window is not defined yet ?

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

0

Where are you calling/defining generateUrl?

Window could be undefinded.

Do a console.log(currentUrl) above the switch statement, see what it prints.

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