====P.S. I found a solution and wrote in comments.
I want to make a form and show its server response in another domain after redirect. A request is sent from /, and server handles the request, then browser sees response from server at /result domain.
Conventionally, It's very simple. This is written as
====index.html====
<form action="/result" method="POST">
<input type="text" placeholder="Your Name" />
<input type="submit" />
</form>
There are more examples like: https://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_post
I want to write React code like above, however, I have difficulty in browser history and redirecting with params. My react looks like below. It doesn't pass browser sent response to /result domain.
====App.js====
function App() {
return (
<BrowserRouter>
<div>
<Switch>
<Route exact path="/">
<Home />
</Route>
<Route path="/result">
<Result />
</Route>
</Switch>
</div>
</BrowserRouter>
);
}
function Home() {
const [submitted, setSubmitted] = useState(false);
const [content, setContent] = useState("");
const history = useHistory();
const handleSubmit = (event) => {
event.preventDefault()
fetch('https://api.example.com')
.then(response => response.json())
setSubmitted(true);
history.push("/"); // because Redirect override history, this line enables browser back button (I guess there should be a smarter way)
}
if (submitted) {
return <Redirect to='/result' /> // I want to pass fetched API response to /result
}
return (
<div>
<h1>Send content to server</h1>
<form onSubmit={handleSubmit}>
<label>
Content:
<input name="content" type="text" {...bindContent} />
</label>
<input type="submit" value="Submit" />
</form>
</div>
);
}
function Result(response) {
return <h2>Browser received {response}</h2>
}