Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda