我想知道是否有一种方法可以在Node.js中呈现页面,然后在2秒后重定向到另一个页面。行间的一些事情:
app.get('/thankyou',function(req,res){
res.render('thankyou' {message : 'Thank you for your submission'});
//after 2 seconds
res.redirect('nextpage');
});
答案 0 :(得分:10)
您必须在模板中执行此操作。服务器代码变为:
app.get('/thankyou',function(req,res){
res.render('thankyou' {message : 'Thank you for your submission'});
});
在模板中添加:
<script>
setTimeout(function () {
// after 2 seconds
window.location = "/next-page";
}, 2000)
</script>