I created an API that handles requests of users registering into my website, but I want the website to redirect them to the home page after they have successfully registered.
The data goes to my database and the server returns success but I don't know why it doesn't route to a different page.
Here is my code:
Signup.js
const submitUser = () => {
Axios.post('http://localhost:3001/api/signUp', {
title: title,
first_name: firstName,
last_name: lastName,
company: company,
phone_type: phoneType,
phone: phone,
email: email,
password:password,
confirm_password:confirm_password
})
.then(() => {
//go to main page
<Route exact path="/" component={HomeIn} />
});
};
server folder index.js:
app.post('/api/signUp', (req, res) => {
const Title = req.body.title
const fname = req.body.first_name
const lname = req.body.last_name
const comp = req.body.company
const pt = req.body.phone_type
const pn = req.body.phone
const email = req.body.email
const password = req.body.password
const confirm_password = req.body.confirm_password
const sqlInsert = "INSERT INTO users (title,first_name,last_name,email,company,phone_type,phone_number,password,confirm_password) VALUES (?,?,?,?,?,?,?,?,?);"
db.query(sqlInsert, [Title,fname,lname,email,comp,pt,pn,password,confirm_password], (err, result) => {
console.log("Success")
});
});