页面间传值

Passing value between pages

当用户右键单击 link 并 选择在新选项卡中打开 link 时,我无法发送数据,但在以下情况下工作正常用户左键单击 link。

<Link to={{pathname: '/student/edit',state:{userId:rowData.id}}}>
  Edit
</Link>

/student/edit是我的Routes

中定义的路径
<Route exact path="/student/edit" component={StudentCandidate}/>

您不能将状态传递给新的 window/tab。相反,您需要将数据作为参数传递:

<Link to={{pathname: '/student/edit', userId: rowData.id}}>
  Edit
</Link>

然后在您的路线中,期待他们在 path

<Route exact path="/student/edit/:userId" component={StudentCandidate}/>

考虑这个类似的 SO question/answer: