Using react-router in with react i have declared some routes like this:
<Route name="voteview" path="voteview/:baselineId" handler={VoteView}/>
In a React Component, i want to call this route. React Router gives me a link:
<Link to="voteview" params={{baselineId: this.props.data.baselineId}}>Voteview</Link>
This results in a <a href...>
link.
But i want to use the url path programmatically, not in an <a href...>
link. How can i get the URL path to the "voteview" route programmatically?
您可以在React Routers上下文中使用makeHref
方法生成如下路径:
this.context.router.makeHref('voteview', {baselineId: this.props.data.baselineId})
As of version version 1.0 of ReactRouter, makeHref(routeName, params, query)
is now createHref(pathname, query)
See the v1.0.0 Upgrade Guide
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.