Hashbang URLs using Ember.js

前端 未结 2 1066
再見小時候
再見小時候 2020-11-30 04:11

I am trying to set up my Router to use \"hashbang\" URLs (#!).

I tried this, but obviously it doesn\'t work:

App.Router.map         


        
2条回答
  •  -上瘾入骨i
    2020-11-30 04:49

    Extending Ember.HashLocation would be the way to go.

    For a clean implementation, you can do the following.

    Ember.Location.registerImplementation('hashbang', Ember.HashLocation.extend({
      // overwrite what you need, for example:
      formatURL: function(url) {
        return '#!' + url;
      }
      // you'll also need to overwrite setURL, getURL, onUpdateURL...
    })
    

    Then instruct your App Router to use your custom implementation for location management:

    App.Router.reopen({
      location: 'hashbang'
    })
    

提交回复
热议问题