如何在 React class 组件中获取参数 ID

How to get params id in react class component

我想要这个 class 组件中 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
            

我确实检查了一些问题,但我没有得到 class 组件

提前致谢

match.paramsRoute's 渲染道具结合使用:

<Switch>
    <Route exact path="/products/:id" render={({ match }) => (
       <AuthChecker>
          <Products id={match.params.id} />
       </AuthChecker>
    )} />
</Switch>