Pass object through Link in react router

后端 未结 6 1193
轮回少年
轮回少年 2020-12-01 07:24

Is it possible to pass an object via Link component in react-router?

Something like:
Click <

6条回答
  •  心在旅途
    2020-12-01 08:16

    So my final conclusion on this question is that I didn't think it through properly. It seemed natural just to pass my data through the Link so I can access them in my Child component. As Colin Ramsay mentioned there is something called state in the Link but that's not the way to do it. It would work fine when the data is passed through Link only if the user clicks on something and is taken to the Child component.

    The problem comes when the user accesses the url which is used in Link then there is no way to get the data.

    So the solution in my case was to pass the ID in Link params and then check if my Store has the data (user accesses it via Link) and then getting this data from the Store.

    Or if the data is not in the Store call the action to fetch the data from the API.

提交回复
热议问题