admin管理员组文章数量:1287626
My react-router is version 4.2.0
I'm trying to accept a POST request to my React application. I may be blind, but I'm unable to find a way to specify a request method (GET, POST) on my routes.
How can I set this up to accept POST requests?
render((
<BrowserRouter>
<div>
<Route exact path="/" history={history} render={() => (
loggedIn()
? (<MyApp />)
: (<Redirect to="/login"/>)
)}/>
<Route exact path="/login" history={history} render={() => (
loggedIn()
? (<Redirect to="/"/>)
: (<Login />)
)}/>
</div>
</BrowserRouter>
), document.getElementById('app'));
Ideally, I would like to have a 3rd route that accepts a POST request to process the POST from a vendor.
I found express-react-router but was unable to locate/install the "express-location" package.
Any help would be appreciated.
My react-router is version 4.2.0
I'm trying to accept a POST request to my React application. I may be blind, but I'm unable to find a way to specify a request method (GET, POST) on my routes.
How can I set this up to accept POST requests?
render((
<BrowserRouter>
<div>
<Route exact path="/" history={history} render={() => (
loggedIn()
? (<MyApp />)
: (<Redirect to="/login"/>)
)}/>
<Route exact path="/login" history={history} render={() => (
loggedIn()
? (<Redirect to="/"/>)
: (<Login />)
)}/>
</div>
</BrowserRouter>
), document.getElementById('app'));
Ideally, I would like to have a 3rd route that accepts a POST request to process the POST from a vendor.
I found express-react-router but was unable to locate/install the "express-location" package.
Any help would be appreciated.
Share Improve this question edited Jan 27, 2021 at 20:28 user3685525 336 bronze badges asked Mar 6, 2018 at 18:13 user3481980user34819801 Answer
Reset to default 7This is client side routing. You cannot post request here. You need to listen to post requests on your express js server.
In your serverjs:
app.post('/',function(req,res){
res.send("hello")
})
That would do the trick.
本文标签: javascriptAccept POST request in reactrouterStack Overflow
版权声明:本文标题:javascript - Accept POST request in react-router - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741308980a2371539.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论