0

I have a react client and I would like to be able to redirect from the express backend.

I've looked through a couple of posts and putting redirect into the body of the response didn't work out. If possible it would be great to redirect on the backend response to the redirect inside the response.

I could maybe replace history with the redirect url inside the response, but I am not sure if that was going to be a good solution ...

Twiggeh
  • 1,030
  • 1
  • 12
  • 24
  • Does this answer your question? [In express how do I redirect a user to an external url?](https://stackoverflow.com/questions/28352871/in-express-how-do-i-redirect-a-user-to-an-external-url) – Incepter Apr 03 '20 at 13:10
  • res.redirect('url') doesn't redirect – Twiggeh Apr 03 '20 at 13:36
  • do you have router in your react client app ? `react-router-dom` – Incepter Apr 03 '20 at 14:01
  • @MohamedELAYADI yes, I do have routing in my client app :) – Twiggeh Apr 03 '20 at 18:12
  • Does this answer your question? [How to manage a redirect request after a jQuery Ajax call](https://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call) – Shlang Apr 11 '20 at 23:49

1 Answers1

0

The appropriate answer seems to be that you listen in react for a body property on the backend apis' response and then redirect to the url specified in the body. I asked because I assumed that React would have something built in for that (and I couldn't find that functionallity :) ).

Twiggeh
  • 1,030
  • 1
  • 12
  • 24