I am trying to create an automatic download after I finish creating a pdf document in the backend and return a url to it in the frontend. I don't want the document to open in the browser from the url, but to start downloading automatically.
I tried to create a fake <a> link in DOM with href and download attributes and then download, but it's open the document in the browser when tried to action click(). This is what I have right now but it downloads a pdf document that fails when opening it.
const file = new Blob([res.data], { type: 'application/pdf' })
const fileURL = URL.createObjectURL(file);
const link = document.createElement('a');
link.href = fileURL;
link.download = "FileName.pdf";
link.click();