Connect中的响应重定向

use*_*402 0 response.redirect connect node.js

在Express中,我可以使用response.redirect(“”)重定向到其他URL。同样,如何在Connect模块中重定向?我已经尝试了以下代码,但无法正常工作。

response.setHeader('Content-Type', 'text/plain');
response.end('<p>302. Redirecting to <a href="' + url+ '">' + url+ '</a></p>');
Run Code Online (Sandbox Code Playgroud)

Svb*_*ker 6

您还可以使用writeHead以下方法在Connect中重定向:

res.writeHead(301, {Location: url});
res.end();
Run Code Online (Sandbox Code Playgroud)

301 http状态代码表示“已永久移动”。