양식이 있고 데이터베이스에 정보를 삽입하고 있습니다. 그 부분은 완벽하게 작동하지만 그 후에 다른 페이지로 어떻게 리디렉션합니까?
app.post('/create', function (req, res) {
Room.findOne({'name' :req.body.name}, function(err,room){
if(err){
return done(err);
}
if(room){
return done(null,false,req.flash('this room name is taken'));
}else{
var newRoom = new Room();
newRoom.name = req.body.name;
newRoom.topic = req.body.topic;
newRoom.participants = req.body.participants;
newRoom.type = req.body.type;
}
newRoom.save(function(err){
if (err){
throw err;
}
redirect: '/home';
})
nodejs 용 http.Response API를 검토하려면 여기 를 참조 하십시오 . response.writeHead (statusCode [, statusMessage] [, 헤더])
이 줄 바꾸기
redirect: '/home';
다음과 함께
res.writeHead(302,{
'Location':'/path',
});
res.end();
리디렉션을위한 상태 코드는 3xx 수준, 예제에서 302는 'found'에 대한 것입니다. 'Location'헤더는 리디렉션 할 경로를 제공합니다.
Express로 작성된 경우 여기를 참조 하고
res.redirect([statusCode,] '/path')
선택적 상태 코드가 명시 적으로 표현되지 않은 경우 기본적으로 302 '발견됨'이됩니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다