如何在 React 的 Get 请求中放置路径变量?

How to place path variable in Get request in React?

    componentDidMount() {
        axios.get('/api/v3/products', {
            params: {
                pageNumber: 1,
                pageSize: 500,
            }
        })

我知道如何在 Get 请求中放置参数,但不知道如何放置路径变量,有人可以帮忙吗?

<Route path='/product/:id' component={Product}/>

试图写“/product/:path”,但我认为它没有任何意义。

示例路线: <Route path='/product/:productId' component={Product}/>

在你的组件里面Product

componentDidMount() {
    const { productId } = this.props.match.params
    // Extracted productId from the Route params.
    axios.get(`/api/v3/product/${productId}`, { // used productId in our GET Request
        params: {
            pageNumber: 1,
            pageSize: 500,
        }
    })
}