[英]res.location is not setting page url in express (MEAN stack)
I require a hard coded password protected page. 我需要一个硬编码的密码保护页面。 I used href to redirect to a page as /admin/user/password:
我使用href重定向为/ admin / user / password的页面:
<a ng-href="/admin/{{user}}/{{password}}" class="form-control btn btn-primary" >Submit</a>
I am using angular $scope.user and $scope.password as my ng-models for input fields. 我正在使用angular $ scope.user和$ scope.password作为输入字段的ng模型。 This request is caught by Express route.get function:
该请求被Express route.get函数捕获:
app.route('/admin/:user/:password')
.get(admin.renderAdmin);
Below is my admin.renderAdmin Page : 以下是我的admin.renderAdmin页面:
exports.renderAdmin = function (req, res) {
console.log("Requested with username and password");
if (req.params.user === "*******" && req.params.password === "******") {
res.location('/admin');
res.render('admin');
} else {
res.send(null);
}
};
/admin is the url that i require and admin.ejs stores the html that i want to render on this url. / admin是我需要的URL,而admin.ejs存储要在此URL上呈现的html。
The output that i am getting is the page renders the admin.ejs but the url is not changing and it is the same as href. 我得到的输出是页面呈现admin.ejs,但URL并未更改,并且与href相同。
Kindly help me on what i might be doing wrong here. 请帮助我解决我可能在这里做错的事情。 Thanks in advance.
提前致谢。
Perhaps try render with a callback? 也许尝试使用回调进行渲染?
// if a callback is specified, the rendered HTML string has to be sent explicitly
res.render('admin', function(err, html) {
res.location('/admin');
res.send(html);
});
Also, if you want the page to actually change, you should use res.redirect()
as opposed to res.location()
. 另外,如果您希望页面实际更改,则应使用
res.redirect()
而不是res.location()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.