Reputation:
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.
Upvotes: 8
Views: 16303
Reputation: 773
This 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.
Upvotes: 7