I want to navigate backwards after clicking a submit button in a form for which I used history.goBack but in case there is no previous page/history, i want to navigate to a screen with thank you message using history.replace.
const handleSubmit = () => {
history.goBack(); // will do nothing if there's no previous history
// If no prev history
history.replace({pathname: `${url}/submit`});
}
Now for the case where there is previous history, history.goBack would navigate to the previous page, but it being asynchronous and history.replace being synchronous, it navigates to the /submit page first and then history.goBack is executed. How do i await the execution of history.goBack?