如何将上下文和道具传递给Reactjs中的<Redirect>组件

时间:2019-09-12 10:51:47

标签: reactjs react-router-component reactjs-native

这是我的要求。

在浏览器上点击路径/ xyz(显示xyz组件)时,我需要导航到单独的路径/ abc(显示abc组件)。

我还需要在导航上将新的道具和上下文传递给目标组件。

我正在寻找

**

<Redirect from="/xyz" to={{pathName: "/abc", component={<AbcComponent context={context} prop1={prop1} prop2={this.props.location.search}}}} />

**

如何在Reactjs中实现这一目标?

1 个答案:

答案 0 :(得分:0)

您不能在“ to”重定向道具中使用“ component”键

您可以通过这种方式== {{pathname =“ / abc”,state = {prop1 = prop1,prop2 = prop2}}}

<Redirect to={{pathName: "/abc", state={context:context,prop:prop1,prop2:props2} }} />

您可以在/ abc上获取数据 通过props.location.state

相关问题