I am using response-router-dom v4. How can I redirect to the page after the form is successfully submitted?
I followed this LINK tutorial . Then I created my own submit function :
const submit=({email='',password=''})=>{
let error={};
let isError=false;
if(email.trim()===''){
error.email='Required';
isError=true;
}
else if(![ 'test@wp.pl' ].includes(email)){
error.email='User does not exist';
isError=true;
}
if(password.trim()===''){
error.password='Required';
isError=true;
}
else if(password!=='test'){
error.password='Wrong password';
isError=true;
}
if(isError){
throw new SubmissionError(error);
}
else{
}
}
There should be a funtion redirect in the comment place, but I have no idea how to do this. I tried to put there:
<Redirect to="/pageAfterSubmit" push />
but nothing happened.
My browser router in index.js is as follows:
<BrowserRouter >
<Provider store={store}>
<div>
<Route path="/" component={LoginForm}></Route>
<Route path="/markers" component={Markers}></Route>
<Route path="/contact" component={Contact}></Route>
</div>
</Provider >
</BrowserRouter>
Thanks for any help.
source
share