【发布时间】:2016-10-25 17:32:19
【问题描述】:
我想为我的应用程序的一部分设置“动态路由”,方法如下:
<Route path="path(/:id)" component={Component} />
到目前为止,这是可行的,但在组件中,我想访问 id 的值,因为它会根据它的不同改变很多东西。我该怎么做?
【问题讨论】:
标签: reactjs react-router react-router-component react-routing
我想为我的应用程序的一部分设置“动态路由”,方法如下:
<Route path="path(/:id)" component={Component} />
到目前为止,这是可行的,但在组件中,我想访问 id 的值,因为它会根据它的不同改变很多东西。我该怎么做?
【问题讨论】:
标签: reactjs react-router react-router-component react-routing
在您的组件中,您可以通过props 访问它。
this.props.params.id
这里是来自 react-router 的指南,其中也有更详细的介绍。 https://github.com/reactjs/react-router-tutorial/tree/master/lessons/06-params
【讨论】: