HTML:
<a href="mysite.com/uploads/asd4a4d5a.pdf" download="foo.pdf">
上传获得唯一的文件名,而真实名称保存在数据库中。我想实现一个简单的文件下载。但是上面的代码重定向到/因为:
$routeProvider.otherwise({ redirectTo: '/',controller: MainController });
我试过
$scope.download = function(resource){ window.open(resource); }
但这只是在一个新的窗口中打开文件。
任何想法如何启用任何文件类型的真正下载?
https://docs.angularjs.org/guide/$location#html-link-rewriting
原文链接:https://www.f2er.com/angularjs/146712.htmlIn cases like the following,links are not rewritten; instead,the
browser will perform a full page reload to the original link.
Links that contain target element Example:
<a href="/ext/link?a=b" target="_self">link</a>
Absolute links that go to a different domain Example:
<a href="http://angularjs.org/">link</a>
Links starting with ‘/’ that lead to a different base path when base is defined Example:
<a href="/not-my-base/link">link</a>
<a target="_self" href="example.com/uploads/asd4a4d5a.pdf" download="foo.pdf">