【问题标题】:render a page in Node and change URL在 Node 中呈现页面并更改 URL
【发布时间】:2017-10-03 08:13:28
【问题描述】:

我有一个具有属性 action="api/login" 的表单登录,登录后,它会呈现一个页面并显示路径名http://localhost:3000/api/login。我想让它说http://localhost:3000/dashboard。我尝试重定向 /dashboard 然后渲染,但我只是得到一个空白页。下面是我的代码。我正在使用 NodeJS,我有一个调用 Auth 控制器的路由文件夹。

//html form
<form method='post' action="api/login">

//route
router
    .route('/login')
    .post(ctrlAuth.login); 



module.exports.login = function(req, res) {

////DOES AUTH CODE STUFF here//////

                        res
                            .status(200)
                            .render('holder', {
                                device: req.session.device,
                                id: req.session.id,
                                first_name: req.session.first_name,
                                last_name: req.session.last_name,
                                role: req.session.role,
                                users: user_data
                            });
                    })

                })



            } else {
                console.log('password incorrect')
                res.redirect('/home')
            }
        });
    })

};

【问题讨论】:

标签: node.js express redirect routes render


【解决方案1】:

您可以在登录后添加res.send({redirect: '/dashboard'});,这应该会重定向到仪表板

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-12
    • 2016-12-25
    • 2020-01-31
    • 2021-05-02
    相关资源
    最近更新 更多