反应路由解析url并将props传递给组件

时间:2017-05-03 14:46:24

标签: reactjs

我的路线定义如下:

<Route path="auth">
   <Route path="confirm-code" component={this.getIndexRoute()} email="xyz@gmail.com" code="1234" />
</Route>

getIndexRoute()为我提供了一个导航组件。当我点击http://localhost:3000/de/auth/confirm-code/时,它就可以了。

但是,我想将此路径修改为http://localhost:3000/de/auth/confirm-code/email=someEmail&code=someCode 然后我想将那些收到的电子邮件和代码作为道具传递给我的组件,以便我可以在那里处理它们。现在我正在硬编码email =“xyz@gmail.com”和代码= 1234。我想从网址中提取它们。

怎么做?

1 个答案:

答案 0 :(得分:2)

所有查询参数(电子邮件,代码)都会自动通过props.location传递给组件 - 或者根据您使用的路由器版本,您可以使用withRouter react-router getting this.props.location in child components

相关问题