Skip to content
Advertisement

ReactJS – Handle POST requests using react router dom

Is there a way to handle POST requests using the react-router-dom (npm) library?

Why? The payment gateway will redirect the user, who successfully payed, back to the platform. I can use a GET or POST request to transfer data with the redirection page. But I don’t like having the data visible in the URL. Other options are always welcome, I’m using a REST API (Node.JS, Express) and a website/dashboard (ReactJS)

Advertisement

Answer

I get what you’re after but you can’t POST to the browser. If you’re uncomfortable passing data as GET params in a URL, you could:

  1. store data in LocalStorage when user submits
  2. deliver server-rendered, static HTML upon redirect that contains purchase information
  3. asynchronously get user’s purchase data upon page load with AJAX or fetch() (or your favorite data-grabbing util).

Since you’re in a React world, I’d recommend the third option here. How to fetch data, build an API endpoint, store data, then display it goes well beyond the scope of this question so I’d suggest some Googling. Here’s a starting point: https://code.tutsplus.com/tutorials/introduction-to-api-calls-with-react-and-axios–cms-21027

Advertisement