我正在使用 express 将表单数据发布到 mongolabs 并且工作正常,但我注意到我在表单发布之后呈现我的 / 页面而不是 /thanks 页面。我正在使用 Express-Handlebars,它正在使用我的 /thanks 模板,但它实际上并没有更改 URL。这是代码:
//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 });
});
我可以做些什么来确保在将数据发布到我的数据库后更改 URL?