首页 > 解决方案 > ExpressJS/NodeJS:res.redirect 不工作

问题描述

我已经编写了用于检查用户是否存在的代码。在此基础上,我们使用 res.redirect 进行重定向。

app.post('/UserRegister', async (req, res, next) => {
    const { username, password } = req.body;
    const isTheir = await User.exists({ username: username});
    console.log(isTheir);
    if (isTheir==true) {
        return next(new AppError("User Already Registered", 501));
    }
    const user = new User({username});
    const registeredUser = await User.register(user, password);
    console.log("Going to Search Flights");
    res.redirect('/searchFlights');    
});

似乎 res.redirect 不起作用,因为它不会 searchFlights 。请帮忙 。

标签: javascriptnode.jsmongodbexpresspassport.js

解决方案


推荐阅读