【问题标题】:Backbone.history: deep urls are not falling backing properly in IEBackbone.history:深层网址在 IE 中没有正确支持
【发布时间】:2013-01-06 07:51:30
【问题描述】:

在我的单页主干应用程序中,我无法让较长的网址在 IE 中正确路由。任何嵌套多于一层的 url,在直接加载它们时都不会收到正确的 hash fallbak。

顶级网址工作正常...

when I load: domain.com/resource
in IE I get: domain.com/#resource (as expected)

导航(应用内)工作正常...

when I click on a link to: domain.com/resource/12345
IE sends me to: domain.com/#resource/12345 (as expected)

但访问更深的网址会直接破坏页面

when I load: domain.com/resource/12345
in IE I get: domain.com/resource/12345 !! this is incorrect, and the page doesn't load

更新:

这是 IE9

【问题讨论】:

  • 您有可以重现此问题的实时页面吗?我想看看,但我手头没有配置 pushState 的服务器来尝试这个。
  • @fencliff- 你可以查看登台服务器stage.change4cancer.org/profile/647955793
  • 问题在 IE9 上重现。如果我发现了什么,我会回复你。
  • @Thomas 你有没有想过如何解决这个问题?

标签: internet-explorer backbone.js pushstate singlepage html5-history


【解决方案1】:

我不确定您在过去 3 小时内是否更改了暂存区的任何内容,但我观察到的问题与此问题有关

IE doesn't support relative paths in the base element when referencing CSS files

当您的页面请求 http://stage.change4cancer.org/profile/647955793 时,它会获取页面的实际 html。现在它是否应该重定向到#profile/647955793 是另一回事(为什么在你已经加载内容之后要这样做,我不确定),但让我解释一下。

在来自http://stage.change4cancer.org/profile/647955793 的 html 中,您有以下标签:

<base href="/" />

但 IE9 不会尊重该标签,除非它具有完整的 URI。因此,所有到 JS、CSS 等的路径都是错误的。而不是

http://stage.change4cancer.org/js/libs/backbone-0.9.2.min.js

它正在请求

http://stage.change4cancer.org/profile/js/libs/backbone-0.9.2.min.js

这实际上返回了另一个 html 页面

由于您的外部 JS 都没有加载,所以当然会出错。

【讨论】:

    【解决方案2】:

    试试这个:

    Backbone.history.start({ pushState: Modernizr.history, silent: true });
    if(!Modernizr.history) {
        var rootLength = Backbone.history.options.root.length;
        var fragment = window.location.pathname.substr(rootLength);
        var search = window.location.search;
        Backbone.history.navigate('/#' + fragment + search, { trigger: true });
    } else {
        Backbone.history.loadUrl(Backbone.history.getFragment())
    }
    

    【讨论】:

      猜你喜欢
      • 2022-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 2021-05-27
      • 1970-01-01
      相关资源
      最近更新 更多