【发布时间】:2021-04-25 22:17:34
【问题描述】:
我想从这个类组件的 url 中得到一个参数 id
App.js
<Switch>
<Route exact path="/products/:id">
<AuthChecker>
<Products />
</AuthChecker>
</Route>
</Switch>
Products.js
import React, { Component } from 'react'
class Products extends Component {
//How to get params id in this class component
render() {
return (
<div>
<h5></h5>
</div>
)
}
}
export default Products
我确实检查了一些问题,但我没有得到类组件
提前致谢
【问题讨论】:
-
你检查类构造函数了吗?
-
我尝试了 match 但它不起作用但现在它通过传递 props match 来工作
标签: reactjs class url parameters react-class-based-component