【问题标题】:Express route not found找不到快速路线
【发布时间】:2015-08-21 05:05:20
【问题描述】:

我对快递的概念还很陌生。无论如何,我正在尝试为某个“计划”构建子路由并执行相应的操作。

我从 mypage.com/someroute/123321312 之类的东西开始

router.get('/:planId', function(req, res, next) {
  //a form is rendered and sent in responce to client
});

工作!

填写呈现的表单后:

<form id="bioData" method="post" action="confirm">

我提交了表单,它会将我重定向到 mypage.com/someroute/123321312/confirm

失败! 404! Url 与尾随 /confirm 路由的预期一致

我想通过在服务器端处理路由来响应触发的请求,如下所示:

router.get('/:planId/confirm', function(req, res, next) {
  //a different page should be rendered
});

为什么 react 不把请求映射到这个路由?

这一定很明显 - 如果您需要更多代码,请询问! :)

【问题讨论】:

    标签: javascript node.js express


    【解决方案1】:

    因为您的方法是post,但映射为get,请更改它!

    router.post('/:planId/confirm', function(req, res, next) {
            ^^
    

    【讨论】:

    • AWWWWWWWW,我知道这一定很明显 - facepalm...我会尽快将其标记为正确 :)