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

507
Vistas
How to download a file on a link click in Nuxt?

I'm coming across an edge case issue where if a user navigates around a few Nuxt routes, clicks the websites "logo" which is an anchor tag back home, then clicks the browsers native back button and then finally clicks a link which is supposed to open a pdf, it redirects to my 404 page.

If the user clicks the pdf link upon page load it behaves as expected. Not sure what is going on here? I tried to add a method to force window.open on the pdf and it is still broken.

Anchor example:

<a
  class="text--uppercase decorate-hover"
  @click.prevent="forceHrefToPdf('Instructions.pdf')"
>
  Instructions 
</a>

Method:

forceHrefToPdf(pdf) {
  window.open(pdf, "_blank")
}

PDF is inside the /root/static directory.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try this one maybe

<template>
  <button @click="downloadMe">download me</button>
</template>

<script>
export default {
  methods: {
    downloadMe() {
      const link = document.createElement('a')
      link.href = '/Instructions.pdf'
      link.download = 'Intructions.pdf'
      link.target = '_blank'
      link.click()
    },
  },
}
</script>

Also, do not use an a tag, it's meant to move from page to page. Rather please use a button who is aimed at doing an action like downloading a PDF. Your client is not the one to decide if it's a link or not (implementation details should not matter here).


Of course, this is also totally feasible but not recommended regarding a11y.

<a href="/Instructions.pdf" target="_blank" download>
  Download my PDF via a link tag
</a>
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