在 react-router 中接受 POST 请求
Accept POST request in react-router
我的 react-router 是 4.2.0 版本
我正在尝试接受对我的 React 应用程序的 POST 请求。我可能是盲人,但我找不到在我的路线上指定请求方法(GET,POST)的方法。
如何设置它以接受 POST 请求?
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'));
理想情况下,我希望有第三条路线接受 POST 请求以处理来自供应商的 POST。
我找到 express-react-router 但无法 locate/install "express-location" 包。
如有任何帮助,我们将不胜感激。
这是客户端路由。您不能在此处 post 请求。
您需要在您的 express js 服务器上收听 post 请求。
在你的服务器中:
app.post('/',function(req,res){
res.send("hello")
})
这样就可以了。
我的 react-router 是 4.2.0 版本
我正在尝试接受对我的 React 应用程序的 POST 请求。我可能是盲人,但我找不到在我的路线上指定请求方法(GET,POST)的方法。
如何设置它以接受 POST 请求?
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'));
理想情况下,我希望有第三条路线接受 POST 请求以处理来自供应商的 POST。
我找到 express-react-router 但无法 locate/install "express-location" 包。
如有任何帮助,我们将不胜感激。
这是客户端路由。您不能在此处 post 请求。 您需要在您的 express js 服务器上收听 post 请求。
在你的服务器中:
app.post('/',function(req,res){
res.send("hello")
})
这样就可以了。