页面重定向在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”)都可以正常工作,但是没有别的。就像它只是忽略了我给它的任何类型的重定向命令。

感谢您的帮助。

lxy1195 回答:页面重定向在Node.JS中被忽略

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

本文链接:https://www.f2er.com/3135286.html

大家都在问