【发布时间】:2019-05-24 13:24:22
【问题描述】:
我用 ReactJS 和 ExpressJS 提出了这个问题:所以基本上用户使用 React 和 axios 上传了一些关于 /info 路由的信息。然后用户从服务器端获取路由参数以重定向到:
axios.post('/info', SomeData)
.then(res => res.data)
.then(data =>{
window.location.replace(`/info/${data.id}`)
})
这是小菜一碟,但是当用户重定向到该页面时出现问题,我需要从该页面获取数据。我可以像这样获取路由参数并在客户端执行请求:
componentDidMount(){
const { match: { params } } = this.props;
axios.get(`/api/info/${params.id}`)
}
但是如何在服务器端获取请求?如何表达访问该“id”以在数据库中搜索它并使用它查询数据以发送回客户端?喜欢:
app.get('/api/info/:id', async (req,res)=>{
await db.find({id: req.params.id}, (data) =>{
res.status(200).send({data})
})
})
有什么帮助吗?谢谢!
【问题讨论】:
标签: javascript node.js regex reactjs express