我在页面中有两个表单模板作为模式(使用Handlebars),网址为/admin
:
<form method="post" action="/admin1"></form> //form1
<form method="post" action="/admin2"></form> //form2
在routes.js文件中:
router.route('/admin').get( controller.index )
router.route('/admin1').get( controller.index )
router.get('/admin1/:sectionCode', controller.sectionForm )
.post('/admin1/:sectionCode', controller.addStudents)
router.get('/admin/:sectionCode', controller.sectionForm )
.post('/admin/:sectionCode', controller.addStudents)
在controller.js中:
async addStudents(req, res) {
try {
let section = req.body
await sectionRepository.addStudentsToSection(section)
res.redirect('/admin')
}catch (err) {
res.status(500).send(err)
}
}
无论我是提交form1还是form2,我都不会被重定向到原来的/admin
页面,并且我在空白页面中得到空括号,尽管浏览器中的网址显示正确的网址。在Chrome浏览器中进行检查:
POST http://localhost:9001/admin 500 (Internal Server Error)
Navigated to http://localhost:9001/admin
如何重定向到表单所在的同一页面:/admin
?