I want to use a setTimeout function to make a redirection after the root file has been displayed in express js example:
app.get('/', (req,res)=>{
res.render('index');
setTimeout(()=>{
res.render('homepage');
},3000)
}
but it seems not to work
You can only render one file. If you want to redirect after it has been displayed, your index file should have some javascript, such as:
<script>
setTimeout(() => {
location.pathname = '/homepage';
}, 3000);
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.