Angularjs simple file download causes router to redirect

https://docs.angularjs.org/guide/$location#html-link-rewriting

In 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="https://stackoverflow.com/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 “https://stackoverflow.com/” that lead to a different base path when base is defined Example:
    <a href="https://stackoverflow.com/not-my-base/link">link</a>

So in your case, you should add a target attribute like so…

<a target="_self" href="https://stackoverflow.com/questions/16670754/example.com/uploads/asd4a4d5a.pdf" download="foo.pdf">

Leave a Comment