簡體   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