Node.js 无法在Nodejs中处理重定向

Node.js 无法在Nodejs中处理重定向,node.js,post,redirect,get,Node.js,Post,Redirect,Get,因此,我在NodeJS中使用了这个POST方法来处理登录身份验证 // Login logic app.post("/home", function(req, res){ Item.findOne({EmailID: req.body.emailAddress}, function (err, docs) { if(req.body.emailAddress === docs.EmailID && hash(req.body

因此,我在NodeJS中使用了这个POST方法来处理登录身份验证

// Login logic
app.post("/home", function(req, res){
    Item.findOne({EmailID: req.body.emailAddress}, function (err, docs) {
     
        if(req.body.emailAddress === docs.EmailID && hash(req.body.password, docs.Salt) === docs.Password) {
          currentUser = docs.FirstName;
          console.log("Damn");
          res.redirect("dashboard.html");
 
  }

});
});
我可以在控制台中看到“Damn”被打印出来,但是由于某种原因,重定向并没有像预期的那样转到下面的GET“dashboard.html”方法,而是转到404错误函数

app.get("/dashboard.html", (req, res)=>{
  console.log("here we go again");
    
    Activity.find({}, function(err, foundItems){
    res.render("home", {newListItems: foundItems});
  });
});
而是转到下面的404函数。控制台上不会打印“又来了”。你知道如何将重定向转到get函数吗

app.get("/*", function(req, res){
  res.sendFile(__dirname + "/404.html")
});
这是我的HTML

  <form class="" action="/home" method="post">
        <div class="">
        <img class ="tent-image"src="assets/images/tent.png" alt width="90" height="72">
        <h4 class="company">PASTIME</h4>
        <h1 class="h3 mb-3 fw-normal"> Sign in</h1>
        <h4 class="h3 fw-normal" style="color: <%= inputcolor %>"> <%= FirstLine %><br /> <%= SecondLine%> </h4>
        <label for="inputEmail" class="virtually-hidden"></label>
        <input id="inputEmail" name="emailID" class="form-control" placeholder="Email address" required="" autofocus="">
        <label for="inputPassword" class="visually-hidden">Password</label>
        <input type="password" name="passWORD" id="inputPassword" class="form-control" placeholder="Password" required="">
        <div class="checkbox mb-3">
          <label>
            <input type="checkbox" value="remember-me"> Remember me
          </label>
        </div>
        <button class="btn btn-dark" type="submit">Submit</button>
        <p class="mt-5 mb-3 text-muted">© 2021 Pastime</p>

      </form>

消遣
登录

密码 记得我吗 提交

©2021消遣

请帮助

尝试使用


res.redirect(“/dashboard.html”)

已经试过了