[英]How do I get the active route pathname in react-router 1?
I have a route defined like: 我有一条定义如下的路线:
<Route path='/invite(/:inviteToken)' component={InvitePage}
key='/invite(/:inviteToken)' onEnter={requireAdmin} />
and the current URL is 当前的URL是
/invite/abc123
In my code, how do I get the current Route, so that I can get the path/key? 在我的代码中,如何获取当前Route,以便获取路径/密钥? (I need that as an index into another array) (我需要作为另一个数组的索引)
From the docs: https://github.com/rackt/react-router/blob/latest/docs/Introduction.md#adding-more-ui 从文档中: https : //github.com/rackt/react-router/blob/latest/docs/Introduction.md#adding-more-ui
<Route path="messages/:id" component={Message} />
Now visits to URLs like inbox/messages/Jkei3c32 will match the new route and build this for you: 现在,访问诸如inbox / messages / Jkei3c32之类的URL将与新路由匹配,并为您构建此路由:
<Message params={{ id: 'Jkei3c32' }}/>
So in your case, you would use this.props.params.inviteToken
in the InvitePage
component. 因此,在您的情况下,可以在InvitePage
组件中使用this.props.params.inviteToken
。
在您的InvitePage
组件中,它应该在this.props.params.inviteToken
下this.props.params.inviteToken
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.