Javascript 使用React路由器从Expressr下载文件
我的server.js上有此路由Javascript 使用React路由器从Expressr下载文件,javascript,reactjs,express,react-router,Javascript,Reactjs,Express,React Router,我的server.js上有此路由 app.get('/api/users/download/:id', auth, admin, (req, res) => { const file = path.resolve(".") + `/uploads/${req.params.id}`; res.download(file) }) 这是我在React中的一部分(使用CRA) 谢谢大家! 一些测试()表明您可以使用 。 常规的 一些测试()表明您可以使用 。 常规的 我不工作,
app.get('/api/users/download/:id', auth, admin, (req, res) => {
const file = path.resolve(".") + `/uploads/${req.params.id}`;
res.download(file)
})
这是我在React中的一部分(使用CRA)
谢谢大家! 一些测试()表明您可以使用
。
- 常规的
。
- 常规的
class AddFile extends Component {
showFileList = () => (
this.state.files ?
this.state.files.map((item,i)=>(
<li key={i}>
<Link to={`/api/users/download/${item}`} target="_blank">
{item}
</Link>
</li>
))
:null
)
}
render() {
return (
<div>
{this.showFileList()}
</div>
);
}
export default AddFile;
const Routes = () => {
return(
<Layout>
<Switch>
<Route path="/admin/add_file" exact component={Auth(AddFile, true)}/>
<Route component={Auth(PageNotFound)}/>
</Switch>
</Layout>
)
}
"proxy": "http://localhost:5000"