我加载了一个带有端点的表单:http://localhost:3000/posts/newpost -- 获取
当我提交表单时,它没有重定向到 posts/save_post 而是重定向到 http://save_post .
当我在操作前面添加帖子时,网址为 http://localhost:3000/posts/posts/save_post
form(role='form', enctype='multipart/form-data', action="/save_post",method="post", style='max-width: 250px;')
//app.js
const posts = require('./routes/post');
app.use('/posts', posts);
posts.js
//get end point
router.get('/newpost',function(req,res){
res.render('new_post');
});
// post endpoint
router.post('/save_post',function(req,res){
console.log(req.body.paper_name);
})
如何从表单调用 post.js 内的 post 路由?
最佳答案
将action="/save_post"
更改为action="/posts/save_post"
。
关于node.js - 表单保存 POST 操作未路由到 Express 中的路由器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49667579/