【发布时间】:2019-03-10 12:46:53
【问题描述】:
我有一个使用 express 作为后端的 react web 应用。
我已对其进行了设置,以便将反应服务器端口 (9000) 上的请求 url 代理到快速服务器 (3000)。问题是,当我输入路径 /examplepath 时,它会返回快速应用程序返回的 json,而不是返回从后端获取响应而呈现的组件。我得到了快速响应并查看它,而不是响应获取快速响应并查看它,然后渲染并向我展示该渲染。
When I click this button, it renders the correct page because it uses this code
componentDidMount() {
axios.post('/', qs.stringify(this.state))
.then(res => {
if (res.data === "session") {
this.setState({session: true})
}
})
}
It will render the page correctly using react
但如果我直接访问路由,它会呈现来自 express 后端的 json 响应。 Like this
当我希望它像使用 react 正确渲染的那样渲染时
devServer: {
port: 9000,
open: true,
proxy: {
'/': 'http://localhost:3000'
}
}
这个 ^ 是我的 webpack.config.js
【问题讨论】:
-
问题还是没有解决
标签: reactjs express networking webpack