最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use dynamic routing in ReactJS with a colon - Stack Overflow

programmeradmin4浏览0评论

I want to change my routing according to product id, which is dynamic.

I found this solution of variables using a colon.

path: "/:product_id" ponent: ProductDetail

How can I use product_id in my ponents.

I want to change my routing according to product id, which is dynamic.

I found this solution of variables using a colon.

path: "/:product_id" ponent: ProductDetail

How can I use product_id in my ponents.

Share Improve this question edited Jan 4, 2019 at 6:23 nem035 35.5k6 gold badges92 silver badges104 bronze badges asked Jan 4, 2019 at 6:19 rajatgalavrajatgalav 3391 gold badge6 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

As explained in the docs, you can access data from the params object on the match prop.

In your case, it would be: match.params.product_id. For example:

function ProductDetail({ match }) {
  return (
    <div>
      <h3>PID: {match.params.product_id}</h3>
    </div>
  );
}
发布评论

评论列表(0)

  1. 暂无评论