location.href在server.js NodeJS中不起作用



在下面的代码中,我试图将它发送到登录页面,但它不起作用。

app.get('/current-pass', (req, res) => {
res.sendFile(path.join(staticPath, "currentPass.html"));
})
app.post('/current-pass', (req, res) => {
let { email, cpassword } = req.body;
if(cpassword.value){
return res.json({ 'alert': "please enter your current password"});
}
db.collection('users').doc(email).get()
.then(user => {
bcrypt.compare(cpassword, user.data().password, (err, result) => {
if(result){
let data = user.data();
return res.json({
location.href = "/login"; // This is not working
})
} else{
return res.json({'alert': 'current password is incorrect'});
}
})
})
})

所有代码都在工作,但location.href不工作。代替

return res.json({
location.href = "/login";
})

我用过

return res.send('success');

但也不起作用

您可以使用res.redirect('/login');使用Express.js进行重定向。请求中没有location变量。

最新更新