在路线中res.redirect('back')之后重新加载页面 [英] Reload a page after res.redirect('back') in route

查看:248
本文介绍了在路线中res.redirect('back')之后重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,它允许您上传图像和创建相册。一切正常,可以接受的是,创建相册后,直到重新加载页面后,新相册才会显示在客户端中,而且我不知道该如何解决。

I'm working on an application which allows you to upload images, and create albums. Everything works fine accept that after an album is created the new album isn't shown in the client until the page is reloaded, and I can't figure out how to solve this.

下面是创建相册的途径。在这种情况下,是否可以使用res.redirect('back')以外的其他方式,以便在路由完成后重新加载页面?

Below is the route for creating an album. Is it somehow possible to use something else than res.redirect('back') in this case so that the page is reloaded after the route has finished?

当然我可以从路径中复制/粘贴代码以首先加载页面,但这要花很多DRY。也许我可以从这条路线内呼叫另一条路线?

Of course I could copy/paste the code from the route for loading the page in the first place, but that would be to much DRY. Maybe I can call the other route from within this route?

路线:

app.post('/album', function(req, res){

    var newAlbum = new albumModel.Album();

    newAlbum.imageName = req.body.albumPicsName;
    newAlbum.imageId = req.body.albumPicsId;
    newAlbum.title = req.body.albumTitle;

    newAlbum.save(function (err) {
        if (err) {
            console.log(err);
            // do something
            console.trace();
        }
        res.redirect('back');
    });
});


推荐答案

您应该能够执行res.redirect(' / album'),而不是强制重新加载,但会获得相同类型的反馈。

You should be able to do res.redirect('/album') instead of back to force a full reload but get the same type of feedback.

这篇关于在路线中res.redirect('back')之后重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆