为什么这 <a href download> HTML 重定向到文件而不是下载?

Why Does This <a href download> HTML Redirect to File Instead of Downloading?

这里是 html:

<!DOCTYPE HTML>
<html>
    <body>
    <a href = "img/test.txt" download> Download </a>
    </body>
</html>

这标识了我正在尝试下载的文件,但它并没有像我期望的“下载”属性那样下载它,它只是重定向到浏览器中的 txt 文件。我在这里做错了什么?

这就是你下载文件的方式,(React env,正如你在聊天中提到的)

import txtFile from '<path_to_txt_file>';

// putting this inside the React component
<a href={txtFile} download="txtFile.txt"> Download Here </a>;