【问题标题】:How to access value of a routing parameter in react?如何在反应中访问路由参数的值?
【发布时间】:2016-10-25 17:32:19
【问题描述】:

我想为我的应用程序的一部分设置“动态路由”,方法如下:

<Route path="path(/:id)" component={Component} />

到目前为止,这是可行的,但在组件中,我想访问 id 的值,因为它会根据它的不同改变很多东西。我该怎么做?

【问题讨论】:

    标签: reactjs react-router react-router-component react-routing


    【解决方案1】:

    在您的组件中,您可以通过props 访问它。

    this.props.params.id
    

    这里是来自 react-router 的指南,其中也有更详细的介绍。 https://github.com/reactjs/react-router-tutorial/tree/master/lessons/06-params

    【讨论】:

    • 谢谢!这正是我想要的。
    猜你喜欢
    • 2020-01-01
    • 2021-05-20
    • 1970-01-01
    • 2021-05-31
    • 2020-09-12
    • 2021-05-03
    • 2021-09-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多