简体   繁体   English

React Router v4.0.0-beta.7

[英]React Router v4.0.0-beta.7

I want to ask about, how to pass parameters by url in React-Router-Dom in beta7. 我想问一下,如何在beta7的React-Router-Dom中通过url传递参数。 Normally i pass params by Button/Link, next get it in URL and finally catch in match.params object. 通常我通过Button / Link传递params,然后在URL中获取它,最后捕获match.params对象。 How to do it in beta7 because i still have no data in my component. 在beta7中怎么做,因为我的组件中仍然没有数据。

Router definition: 路由器定义:

<Route path='/users/:_id/edit' component={UsersEdit}/>

How I pass params: 我如何传递参数:

<Button size='small' as={Link} to={`/users/${_id}/edit`} content='Edit'/>

my url: 我的网址:

url: "/users/8aTwvLKcWiXopSj2e/edit"

params: nothing. 参数:什么都没有。 https://i.stack.imgur.com/bjUp4.png https://i.stack.imgur.com/bjUp4.png

I found a solution. 我找到了解决方案。 Just anchor a function to a button, and pass params like this: 只需将函数锚定到按钮,然后传递如下参数:

 editUser: ({}, user,) => {
     push(`/users/${user.id}/edit`, {userId: user.id})
 }

then in location.state (in redirected component) you will be have a parameter for my example userId 然后在location.state (在重定向的组件中),您将拥有我的示例userId的参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM