Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 - Html link to file download routes to home after click

I have an Angular2 application that expose some direct download links to files.

The files are located under :

[MY_APP_FOLDER]\src\assets\OffertFile

An example of the link href is this:

/assets/OffertFile/test.xlsx

The component.html link example is this:

<a href="/assets/OffertFile/test.xlsx" target="_self">
      <i class="fa fa-download fa-2x text-primary" aria-hidden="true"></i>
</a>

The link works, I can download the file. The problem is that once I click the link, the application routes to home...

How can I avoid this?

Thanks to support

like image 861
DarioN1 Avatar asked Dec 14 '22 23:12

DarioN1


1 Answers

Please add the download attribute to the <a> tag. This will prevent rout changes and tell the browser it is a download link:

HTML docs: https://www.w3schools.com/tags/tag_a.asp

<a href="/assets/OffertFile/test.xlsx" target="_self" download>
      <i class="fa fa-download fa-2x text-primary" aria-hidden="true"></i>
</a>
like image 54
Ahmed Musallam Avatar answered Dec 28 '22 10:12

Ahmed Musallam