【发布时间】:2020-01-13 00:03:58
【问题描述】:
我在 stories.jsx 文件中有一个 div(图像),我需要给它 onClick 函数。我如何制作handeClick 函数,让我转到下一页story.jsx(故事API)?当点击其中一个时,此 API 将为它拥有的每个 div(图像)显示不同的故事。
我的图像位于公共(静态)文件夹中,我使用name、storyText 和imagePath 将它们保存在 MongoDB 中。但是我需要一个带有history.push(/nextpath) 的句柄函数,才能让我进入故事页面的第一个页面,具体取决于我单击的图像。要么是那个函数,要么是当我按下图像时给我 id 的函数,然后用window.location 将我带到图像。
我也不知道,我是新手。我将如何通过实际示例准确使用history.push(/nextpath) 或其他东西?这是我的this.state,下面是我的 stories.jsx 文件中的render(){}。我该怎么办?
constructor(props) {
super(props);
this.state = {
items: []
};
这会将所有图像获取到story.jsx:
router.get("/slike", (req, res) => {
Slike.find((err, result) => {
console.log(err);
console.log(result);
res.send(result);
});
});
这会从 stories.jsx 中获取一张图片:
router.get("/slike/:id", (req, res) => {
Slike.findById(req.params.id, (err, result) => {
res.send(result);
});
});
【问题讨论】:
-
你在使用 react-router-dom?
-
我会,但不是在这两个文件上,我用它来路由应用程序的其余部分,但即使这样我也不知道如何在这里使用
-
反应我的意思是在你的服务器上表达如果你想路径参数来路由检查这个:reacttraining.com/react-router/web/example/url-params
标签: node.js reactjs express react-router