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 user3481980user3481980
Add a ment  | 

1 Answer 1

Reset to default 7

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.

本文标签: javascriptAccept POST request in reactrouterStack Overflow