Ada*_*dam 12 url redirect node.js
我正在尝试以这种方式重定向node.js中我的应用程序的url:
// response comes from the http server
response.statusCode = 302;
response.setHeader("Location", "/page");
response.end();
Run Code Online (Sandbox Code Playgroud)
但是当前的页面与新的页面混合在一起,看起来很奇怪:| 我的解决方案看起来完全合乎逻辑,我不知道为什么会发生这种情况,但如果我在重定向后重新加载页面就可以了.
无论如何,在节点中进行HTTP重定向的正确方法是什么?
看起来快递就像你的方式一样.从我可以看到的差异是他们推动一些身体内容和使用绝对网址.
请参阅express response.redirect方法:
https://github.com/visionmedia/express/blob/master/lib/response.js#L335
// Support text/{plain,html} by default
if (req.accepts('html')) {
body = '<p>' + http.STATUS_CODES[status] + '. Redirecting to <a href="' + url + '">' + url + '</a></p>';
this.header('Content-Type', 'text/html');
} else {
body = http.STATUS_CODES[status] + '. Redirecting to ' + url;
this.header('Content-Type', 'text/plain');
}
// Respond
this.statusCode = status;
this.header('Location', url);
this.end(body);
};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
22989 次 |
最近记录: |