Backbone.js PushStates: Fallback for Internet Explorer not working

前端 未结 1 901
说谎
说谎 2020-12-31 23:32

My site has just implemented pushstates in Backbone.js and the entire site breaks for IE. How should I create a fallback for IE?

What I am trying to achieve<

相关标签:
1条回答
  • 2021-01-01 00:16

    If you don't want http://mydomain.com/explore/#explore url, then you have to redirect to http://mydomain.com/#explore so Backbone will start with it instead.

    if(!pushState && window.location.pathname != "/") {
      window.location.replace("/#" + window.location.pathname)
    }
    

    UPD: you'll probably have to remove the leading slash when setting path as a hash window.location.pathname.substr(1)

    UPD2: if you want /explore/ to be the root for your backbone routes then you have to exclude it from routes and set as a root in History.start({root: "/explore/"})

    routes: {
        '': 'explore',
        ':id': 'viewListing',
    }
    
    0 讨论(0)
提交回复
热议问题