I am using express to Post form data to mongolabs and it's working fine, but I noticed that I am rendering my / page after the form posts instead of the /thanks page. I am using Express-Handlebars and it is using my /thanks template, but it's not actually changing the URL. Here is the code:
//get index view
app.get('/', function (req, res) {
//ask Mongo for Form model
Form.find({}, (err, data) => {
if (err) throw err;
res.render('index')
});
});
app.post('/', urlencodedParser, (req, res) => {
//get data from the view and add it to Mongo
var newForm = Form(req.body).save((err, data) => {
if (err) throw err;
//jsonify the form data
res.json(data);
});
res.redirect('/thanks', {form: req.body });
});
What can I do to ensure that I change URLs after posting data to my DB?