在使用主干历史记录/推送状态时有问题-但仅限于不支持它的浏览器(旧IE)
问题是这样的。当我第一次访问/en_gb/dashboard时,所有的东西都可以在所有的浏览器中运行。然而,在IE<=9中,它将#dashboard附加到地址栏,形成/en_gb/dashboard#dashboard。现在,当我点击刷新时,我的路由器不会触发。
并不是我的所有站点都在主干控制下-所以路由器正在工作:
routes: {
'dashboard': 'showDashboard'
}我的引导程序如下所示:
if (Backbone.history) {
var pushStateSupported = _.isFunction(history.pushState);
var urlRoot = '/en_gb/';
var enableSilent = !pushStateSupported;
Backbone.history.start({
pushState: pushStateSupported,
root: urlRoot,
silent: enableSilent
});
if (!pushStateSupported) {
Backbone.history.navigate(window.location.pathname.substring(urlRoot.length), { trigger: true });
}
}添加调试,我可以看到Backbone.history.navigate()总是被调用,但是当散列存在时,trigger: true似乎没有被拾取。
发布于 2013-04-19 19:22:12
嗯-我似乎已经修复了它-虽然不是一个优雅的解决方案,但这确实为我解决了它:
if (!pushStateSupported) {
var route = window.location.pathname.substring(urlRoot.length);
Backbone.history.navigate('/#' + route, { trigger: true });
}它并不优雅,因为地址栏中的URL显示为/en_gb/dashboard##dashboard --但它现在正在通过Backbone.navigate()方法。在此之前,它在
if (this.fragment === fragment) return;https://stackoverflow.com/questions/16102842
复制相似问题