Angular2-单击后指向指向首页的文件下载路由的HTML链接 [英] Angular2 - Html link to file download routes to home after click

查看:70
本文介绍了Angular2-单击后指向指向首页的文件下载路由的HTML链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Angular2 应用程序,该应用程序公开了一些直接下载到文件的链接.

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

文件位于:

[MY_APP_FOLDER]\src\assets\OffertFile

链接href的示例如下:

An example of the link href is this:

/assets/OffertFile/test.xlsx

component.html链接示例为:

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...

如何避免这种情况?

感谢支持

推荐答案

请在<a>标签中添加download属性.这样可以防止路由变化,并告诉浏览器它是一个下载链接:

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

HTML文档: 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>

这篇关于Angular2-单击后指向指向首页的文件下载路由的HTML链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆