繁体   English   中英

页面重定向在 Node.JS 中被忽略

[英]Page redirect is being ignored in Node.JS

文件夹是这样设置的

-上市

 -landing
      -landing.html
 -Login
      -login.html
 -register
       -register.html

-路线

 -HTMLroutes
 -APIroutes

- server.js

被注释掉的所有东西都是我尝试过但没有成功的东西

if (bcrypt.compare(req.body.user.password, user.Password)){

            console.log("successful login")
            // res.send({redirect: '/app'}) 
            // res.redirect("app")
            // return res.redirect("/app")
            // res.sendFile(path.join("./public/landing/landing.html"))
            // res.sendFile('./landing/landing.html', { root: "public" })

}

Landing.html 是我希望用户看到的页面。 我是通过将路由重定向到“/app”之类的东西还是通过加载页面来加载它。

“res.sendFile(path.join ...)”是我最了解的,但我的错误说文件路径不是“绝对”

在我的 server.js 中,我使用 express.static("public"),我知道它以某种方式起作用

但是每次我测试这个时,我都会得到 console.log("successful login") 工作,但没有别的。 就像它只是忽略我给它的任何类型的重定向命令。

谢谢你的帮助。

我假设res.sendFile需要一个绝对路径。 您可以使用path.resolve获取绝对路径, path.join将只是“加入”或将路径放在一起,路径将“相对”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM