作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我在 React 前端使用代理服务器,在后端使用 Go 服务器。当我不使用 react 或代理服务器时,重定向工作正常。但是,当我使用 React 及其开发服务器和我的 Go 后端的代理时,重定向不会执行任何操作。
// React package.json file
"proxy": "http://localhost:5000", // proxy to golang hosted on 5000
"scripts": {
"start": "react-scripts start",
},
-----------------------
// golang server
func main() {
router := gin.Default()
router.Use(static.Serve("/", static.LocalFile("../client/public", true)))
ping := router.Group("/path")
ping.GET("/ping", pingFunc)
ping.POST("/ping", pingFuncPost)
router.Run(":5000")
}
// This redirect is not working.
// In the terminal it shows that a redirect is made but on the frontend
// nothing occurs
func pingFuncPost( c *gin.Context)
{
http.Redirect(c.Writer, c.Request, "/page", http.StatusSeeOther)`
}
最佳答案
你重定向,用
const data = {"query": this.state.query};
fetch(`/path/ping`, { // should hit the end point of pingFuncPost in golang server, which should redirect to localhost:3000/results
method: 'POST',
body: JSON.stringify(data),
})
.then(res => res.json())
.then(res => {
<Redirect to="/somewhere/else" />
})
关于reactjs - 服务器重定向不适用于 ReactJS 代理服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56030553/
我是一名优秀的程序员,十分优秀!