Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取react路由器中某个路由的路径_Javascript_Reactjs_React Router - Fatal编程技术网

Javascript 获取react路由器中某个路由的路径

Javascript 获取react路由器中某个路由的路径,javascript,reactjs,react-router,Javascript,Reactjs,React Router,在react中使用react路由器,我声明了如下一些路由: <Route name="voteview" path="voteview/:baselineId" handler={VoteView}/> 在React组件中,我想调用此路由。 React路由器给了我一个链接: <Link to="voteview" params={{baselineId: this.props.data.baselineId}}>Voteview</Link> Vote

在react中使用react路由器,我声明了如下一些路由:

<Route name="voteview" path="voteview/:baselineId" handler={VoteView}/>

在React组件中,我想调用此路由。 React路由器给了我一个链接:

<Link to="voteview" params={{baselineId: this.props.data.baselineId}}>Voteview</Link>
Voteview
这会产生一个
链接


但是我想以编程方式使用url路径,而不是在
链接中。如何以编程方式获取“voteview”路由的URL路径?

您可以在React Routers上下文中使用
makeHref
方法生成如下路径:

this.context.router.makeHref('voteview', {baselineId: this.props.data.baselineId})

您可以在React Routers上下文中使用
makeHref
方法生成如下路径:

this.context.router.makeHref('voteview', {baselineId: this.props.data.baselineId})

从ReactRouter的1.0版开始,
makeHref(routeName,params,query)
现在是
createHref(路径名,query)


查看1.0.0版的ReactRouter,从1.0版开始,
makeHref(routeName,params,query)
现在是
createHref(路径名,query)

请参阅v1.0.0