react-router-dom provides some handy hooks. In your case, I’d suggest useParams() (link to docs)
import { useParams } from 'react-router-dom';
function MyComponent {
let { id } = useParams();
return (<p>{id}</p>);
}
I’d also probably opt for not using withRouter if you will be using the hooks provided by React Router