Backbone.history是不是在IE 9后退按钮更新破 [英] Backbone.history is not updating in IE 9. Back button broken

查看:186
本文介绍了Backbone.history是不是在IE 9后退按钮更新破的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用程序,我们实际上有两个骨干SPA的应用程序。第一个是用于登录,注册和其他功能未经验证的用户。造成这种情况的URL将类似 http://www.example.com/registration#signin 。一旦你登录,您将被重定向到我们的主要骨干的应用程序在 http://www.example.com/ui#家

In our app, we actually have two Backbone SPA applications. The first one is for login, registration and other features for unauthenticated users. The URL for this would be something like http://www.example.com/registration#signin. Once you login, you are redirected to our main Backbone app at http://www.example.com/ui#home.

在我的主要用户界面的应用程序中,我使用Backbone.history的没有的pushState的。该应用程序文件看起来是这样的:

In my main UI app, I am using Backbone.history without pushState. The App file looks something like:

define(function (require) {    
    var App = new Marionette.Application();

    App.addInitializer(function (options) {
        ...
    });

    ...

    App.on('initialize:after', function () {
        $(function(){
            if (Backbone.history) {
                Backbone.history.start({ root: '/ui' });
            }
        });
        $.log("**WebApp**: Marionette app started.");
    });

    return App;
});

当然,一切都完美的作品,除了IE 9浏览器的任何(也许10,我需要检查)。在IE 9,所有的路由工作正常。点击链接,如 http://www.example.com/ui#anotherpage 工作。 然而,当用户点击浏览器中的后退按钮,它们不会发送回发射的最后途径。相反,他们被送到 http://www.example.com/registration#signin ,该是节点,我们的Web服务器提供服务的最后一页。当我点击通过链接,我可以看到history.length和Backbone.history.history.length没有更新。

Of course, everything works flawlessly in any browser except IE 9 (and maybe 10, I need to check). In IE 9, all the routing works fine. Clicking links such as http://www.example.com/ui#anotherpage works. However, when the user clicks the Back button in their browser, they are not sent back to the last route fired. Instead, they are sent to http://www.example.com/registration#signin, which is the last page served by Node, our web server. As I click through links, I can see that history.length and Backbone.history.history.length are not updating.

所有的路线是从链接/ URL的解雇。我不使用router.navigate()的code之内。这是我们的路由器例子:

All routes are fired from links/URL's. I'm not using router.navigate() within the code. Here are examples of our Router:

define(function (require) {
    var Backbone = require('backbone'),
        Marionette = require('marionette');

    return Backbone.Marionette.AppRouter.extend({
        appRoutes: {
            "": "showHome",
            "home": "showHome",
            "foo": "showFoo"
        }
    });
});

和控制器:

define(function (require) {
    var Backbone = require('backbone'),
        Marionette = require('marionette');

    return Backbone.Marionette.Controller.extend({
        showHome: function () {
            require(['webapp','modules/home'], function (WebApp) {
                WebApp.module("Home").start();
                WebApp.module("Home").controller.showModule();
            });
        },
        showFoo: function () {
            require(['webapp', 'modules/foo'], function (WebApp) {
                WebApp.module("Foo").start();
                WebApp.module("Foo").controller.showModule();
            });
        }
    });
});

更新:

在进一步的研究,原来的问题是,旧版本的IE不记录在他们的历史散列的变化。见 - <一个href=\"http://stackoverflow.com/questions/5601864/change-location-hash-and-then-$p$pss-back-button-ie-behaves-differently-from-ot\">Change的location.hash然后preSS后退按钮 - IE浏览器的行为不同于其他浏览器的。但我还是不知道这个解决方法是什么。我猜它会以某种方式手动处理涉及哈希改变事件与插件如的 jQuery的Hashchange 和做...什么?手动设置IE浏览器的历史?或者制作一个自定义的历史对象,并使用它,当我们在IE中检测到后退按钮?

On further research, it turns out the problem is that older versions of IE don't record hash changes in their history. See - Change location.hash and then press Back button - IE behaves differently from other browsers. But I'm still not sure what the workaround for this would be. I'm guessing it would somehow involve manually handling hash change events with a plugin such as jQuery Hashchange and doing... something? Manually setting IE's history? Or crafting a custom history object and using it when we detect a Back button in IE?

推荐答案

我是有在我们的IE浏览器的应用程序之一了同样的问题。
启动骨干历史像下面的工作。

I was having the same problem in one of our apps for IE. Starting backbone history like below works.

Backbone.history.start({
            pushState: true,
            hashChange: false
        });

更新:由于提到阮云道,
当你设置pushState的为真,哈希的URL不再触发路线。除非你添加的所有骨干路由服务器端支持,你需要在捕捉适当的环节和途径

这篇关于Backbone.history是不是在IE 9后退按钮更新破的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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