You can use the useParams hook or wrap a class based component with the withRouter HOC from react-router. You can see an example in their documentation.
Using functional components
import React, {useEffect} from 'react';
import {useParams} from 'react-router-dom';
function Child() {
// We can use the `useParams` hook here to access
// the dynamic pieces of the URL.
let { id } = useParams();
useEffect(() => {
fetch(MyGlobleSetting.url + 'product/'+ id)
.then(response => response.json())
.then(json => this.setState({ singleProduct: json.data }));
}, [])
}
Using a class component
import React, {Component} from 'react';
import { withRouter } from 'react-router-dom';
class myComponent extends Component {
componentDidMount(){
const {match} = this.props
fetch(MyGlobleSetting.url + 'product/'+ match.params.id)
.then(response => response.json())
.then(json => this.setState({ singleProduct: json.data }));
}
}
export default withRouter(Child);