【问题标题】:res.redirect() not working in chrome - Found. Redirecting tores.redirect() 在 chrome 中不起作用 - 找到。重定向到
【发布时间】:2017-11-26 17:09:21
【问题描述】:

得到这个奇怪的

这是 express.js 中的 post call,其中包含重定向。

app.post('/callback', (req, res)=> {
res.redirect('/deal')
});

这是我在 express.js 中的调用

app.get('/deal', (req, res) => {
     console.log("node.js /deal")
});

以上工作正常

更新: 真正的麻烦。

快递:

app.post('/callback', (req, res)=> {
    res.redirect('')
    });

angular2-cli:

path: '',
redirectTo: '/deals'
component: PublicDealsComponent

为什么我说奇怪的是它在 Microsoft-edge 中完美运行,但在 chrome 中却不行。是什么原因?如何让它在 chrome 中工作?

【问题讨论】:

  • 你在控制台得到什么输出?
  • 在网络面板中签入时,响应标头看起来都正常?
  • @professionallyme86 你能看看更新一。在此,控制台中没有输出(empty)。
  • @CBroe 看起来不错(并且看起来与 microsoft-edge 相同)。常规:请求 URL:localhost:3000/callback 请求方法:POST 状态代码:302 找到(黄色)远程地址:[::1]:3000 推荐人策略:no-referrer-when-downgrade
  • 是的,我可以在最后重现这个问题。这是因为您试图重定向到空字符串。

标签: javascript node.js google-chrome express redirect


【解决方案1】:

发生这种情况是因为您无法将用户重定向到空的string ('')。 如果你想重定向到你的主路由,最后没有'/',那么你实际上可以使用请求中的req.protocolreq.host。您可以参考以下代码:

res.redirect(req.protocol + '://' + req.get('host'));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多