如何使用history.push(/ nextpath)或windows.location?

时间:2019-09-11 07:30:36

标签: node.js reactjs express react-router

我需要为其提供onClick函数的story.jsx文件中的一个div(图像)。如何使handeClick函数使我转到下一页,进入story.jsx(story API)?当点击其中一个div(图像)时,该API将为每个div(图像)显示不同的故事。

我的图像位于public(静态)文件夹中,我分别用namestoryTextimagePath将它们保存在MongoDB中。但是我需要使用history.push(/nextpath)的handle函数,才能使我进入故事页面的1,具体取决于我单击的图像。要么是当我按下图像然后使用window.location带我到图像时给我id的函数。

我也不知道,我是新手。在实际示例中,我将如何正确使用history.push(/nextpath)或其他东西?这是我的this.state,下面是我的story.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);
  });
});

这会从story.jsx中获取一张图片:

router.get("/slike/:id", (req, res) => {
  Slike.findById(req.params.id, (err, result) => {
    res.send(result);
  });
});

1 个答案:

答案 0 :(得分:0)

您可以使用它来做到这一点。

'2019-09-11 15:44:25'