'res.location(path)'什么都不做? (表示) [英] 'res.location(path)' does not do anything? (Express)

查看:110
本文介绍了'res.location(path)'什么都不做? (表示)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找有关 Stack Overflow 的答案;非有效...为什么res.location(path)不起作用?我的位置标题不变.普通渲染效果很好.

I have been searching around for answers on Stack Overflow; non have worked... Why does res.location(path) not work? My Location-header does not change. Normal rendering works fine.

我可以添加,在最终代码中,我想呈现页面.因此,我想用res.render('app', {...})替换res.end()并使用 handlebars.js 进行渲染.

I could add, that in the final code, I want to render the page. So, I want to replace res.end() with res.render('app', {...}) and use handlebars.js for rendering.

代码无法正常工作:

app.get('/sub-link/:wildcard', (req, res) => {
    res.location('/new-header');
    res.end();
});

我一直在阅读文档;找不到原因.我发现唯一可能是问题的是浏览器:

I have been reading the documentation; could not find the reason. The only thing I found that could be the problem, is the browser:

对URL进行编码后,如果尚未进行编码,则Express会通过 在Location标头中指定浏览器的URL,没有任何 验证.

浏览器负责从获取预期的网址 当前URL或引荐URL,以及在中指定的URL 位置标头;并相应地重定向用户.

Browsers take the responsibility of deriving the intended URL from the current URL or the referring URL, and the URL specified in the Location header; and redirect the user accordingly.

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