简体   繁体   中英

Page redirect is being ignored in Node.JS

folders are set up like this

-public

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

-routes

 -HTMLroutes
 -APIroutes

- server.js

everything that is commented out are things ive tried with no success

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 is the page i want the user to see. whether i load it by redirecting the route to something like "/app" or by loading the page.

"res.sendFile(path.join...)" is what i got furthest with but my error says the file path is not "Absolute"

in my server.js i use express.static("public"), i know that plays a role somehow

however every time i test this, i get console.log("successful login") working but nothing else. Like it just ignores any type of redirect command i give it.

thanks for any help.

I assume res.sendFile needs a absolute path. You can use path.resolve to get a absolute path, path.join will just "join" or put the paths together and the path will "relative"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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