Reactjs 反应应用程序代理在<;路线>;包含url参数
我有一个create react应用程序,通过代理与express服务器对话 当我从大多数组件发布时,代理可以工作,但如果该组件通过包含url参数的路由呈现,则请求url将更改为不存在的内容,并导致404 My express服务器终结点(在端口5000上侦听) 这可以成功地卷曲 这是从包含方法的react组件窗体调用的Reactjs 反应应用程序代理在<;路线>;包含url参数,reactjs,react-router,Reactjs,React Router,我有一个create react应用程序,通过代理与express服务器对话 当我从大多数组件发布时,代理可以工作,但如果该组件通过包含url参数的路由呈现,则请求url将更改为不存在的内容,并导致404 My express服务器终结点(在端口5000上侦听) 这可以成功地卷曲 这是从包含方法的react组件窗体调用的 handleSubmit = (e) => { e.preventDefault(); const { hash } = this
handleSubmit = (e) => {
e.preventDefault();
const { hash } = this.props.match.params;
axios.post( api/create-account, {hash:hash});
};
路线包括:
<Switch>
<Route exact path='/' component={Home}/>
{/*<Route path='/create-account/:hash' component={CreateAccountForm}/>*/}
request is sent to create-account/api/create-account resulting in 404
<Route path='/create-account' component={CreateAccountForm}/>
request is sent to /api/create-account )resulting in 200
<Route path='/' component={Home}/>
</Switch>
在添加代理之前,这一切都很正常(将post URL硬编码到localhost:5000/api/create account)
这是在我引入代理之后才开始发生的
我做错了什么?谢谢我自己刚解决了这个问题 答案就在这里 我需要在我的帖子请求中添加前导斜杠
handleSubmit = (e) => {
e.preventDefault();
const { hash } = this.props.match.params;
axios.post( api/create-account, {hash:hash});
};
"proxy": "http://localhost:5000",
handleSubmit = (e) => {
e.preventDefault();
const { hash } = this.props.match.params;
axios.post( api/create-account, {hash:hash});
};