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

I want to change my routing according to product id, which is dynamic.I found this solution of variable

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>
  );
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744210809a4563323.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信