0

I have a simple HTML form:

<form method="post" action="http://localhost:3000">
    <input value="val" name="nam" />
    <button type="submit">Launch</button>
</form>

Now I have a react application which runs on localhost:3000 as follow:

import React from 'react';
import ReactDOM from 'react-dom';
import App from 'components/App/App';

class IndexClass extends React.Component {
    render() {
        return (
            <BrowserRouter>
                <Switch>
                    <Route path="/" exact component={App}/>
                </Switch>
            </BrowserRouter>
        );
    }
}

ReactDOM.render(<Index/>, document.getElementById('root'));


Now, If I type localhost:3000 in my browser url bar, I can successfully launch the application. But If I try to launch my application from simple html form, I get an error:

Cannot POST\

Screenshot:

https://cdn.pbrd.co/images/I0My0wZ.png

I think this is because of post method. How do I solve it?

  • `http://localhost:3000/` use this instead of localhost:3000 in html form – Dhaval Patel Feb 12 '19 at 07:12
  • How do you launch the app on localhost? Is it simply a `create-react-app` and `npm start`? Most likely the development server doesn't support `POST` method and you need to implement it. – pawel Feb 12 '19 at 07:14
  • Yes, That I want to know that How will it support POST? – Prateek Agrawal Feb 12 '19 at 07:27
  • It is working fine with GET – Prateek Agrawal Feb 12 '19 at 07:27
  • @PrateekAgrawal calling an entire react app from a form action seems odd. maybe you are approaching the base problem incorrectly, kindly explain your approach for this code. we are here to help – Varun Suresh Kumar Feb 12 '19 at 07:33
  • My react app won't be public. It will be called by some other application which is written in another programming language. To launch my app, post request will be used and they will redirect to my application. That's by I added sample HTML form which will send post request to my react app. Finally user will be redirected to my react application – Prateek Agrawal Feb 12 '19 at 07:43
  • I can't use get request since some data which will be passed not be be shown in url bar – Prateek Agrawal Feb 12 '19 at 07:44
  • @PrateekAgrawal Did you find an way? – Worth Lutz Apr 09 '20 at 16:53

0 Answers0