简体   繁体   English

使用 Express 后端重定向 React 前端

[英]Redirect React frontend with Express backend

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...我也许可以用响应中的重定向 url 替换历史记录,但我不确定这是否是一个好的解决方案......

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.适当的答案似乎是您在后端 api 的响应中监听 body 属性,然后重定向到 body 中指定的 url。 I asked because I assumed that React would have something built in for that (and I couldn't find that functionallity:) ).我问是因为我认为 React 会为此内置一些东西(我找不到那个功能:))。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM