寫我的快車應用程序我碰到這個錯誤,我不確定該怎麼辦?使用快遞4.14,我不知道該怎麼做,它正在尋找它的說法,但我目前沒有給它一個地位。事件看着他們的文檔,他們不給他們的示例路線的地位。明確反對res.redirect(網址,狀態):使用res.redirect(狀態,網址)
express deprecated res.redirect(url, status): Use res.redirect(status, url)
這裏是我的代碼:
router.post("/event", isLoggedIn, function (req,res){
// get data from form and add to events array
var title = req.body.title;
var date = req.body.date;
var description = req.body.description;
var venue = req.body.venue;
var photo = req.body.photo;
var category = req.body.category;
//get user data to save to the user
var owner = {
id: req.user._id,
username: req.user.username
}
var newEvent = {category: category, title: title, date: date, description: description, venue: venue, photos:{link: photo,date: date}, owner: owner};
Event.create(newEvent, function(err, event){
if(err){
console.log(err)
} else {
//This takes the event owner ID and saves it into the model
event.owner.id = req.user._id;
//This takes the event username and saves it into the model
event.owner.username = req.user.username;
event.save();
console.log(event);
res.render('events',{events: event}); }
})
})
你有任何的代碼在應用程序中使用'redirect'方法?在你提供的示例中 - 重定向沒有被使用 – drinchev
OH,是的,我認爲最後一行應該是重定向而不是渲染,我必須在發佈之前嘗試過並錯過了它。 – illcrx