Facebook回调已经开始追加#_=_哈希下划线返回URL
有人知道为什么吗?解决方案是什么?
Facebook回调已经开始追加#_=_哈希下划线返回URL
有人知道为什么吗?解决方案是什么?
当前回答
如果你使用vue-router,你可以添加到路由列表:
{
path: '/_=_',
redirect: '/', // <-- or other default route
},
其他回答
Facebook最近在处理会话重定向的方式上做出了改变。有关公告,请参阅本周Operation Developer Love博客文章中的“会话重定向行为的更改”。
如果你使用vue-router,你可以添加到路由列表:
{
path: '/_=_',
redirect: '/', // <-- or other default route
},
如果你使用的是带有hashbang (/#!/) url的JS框架,比如Angular,这可能会成为一个严重的问题。实际上,Angular会认为带有非hashbang片段的url是无效的,并抛出一个错误:
Error: Invalid url "http://example.com/#_=_", missing hash prefix "#!".
如果你在这种情况下(重定向到你的域根目录),不要这样做:
window.location.hash = ''; // goes to /#, which is no better
简单地做:
window.location.hash = '!'; // goes to /#!, which allows Angular to take care of the rest
你也可以在Facebook回调的redirect_uri参数上指定你自己的散列,这在某些情况下可能是有帮助的,例如/api/account/callback#home。当你被重定向回来,它至少是一个哈希,对应于一个已知的路由,如果你使用backbone.js或类似的(不确定jquery移动)。
如果您想从url中删除剩余的“#”
$(window).on('load', function(e){
if (window.location.hash == '#_=_') {
window.location.hash = ''; // for older browsers, leaves a # behind
history.pushState('', document.title, window.location.pathname); // nice and clean
e.preventDefault(); // no page reload
}
})