tehmaestro
tehmaestro

Reputation: 1060

Ember.js get location type at runtime

How can I get the location type inside an initializer, in EmberJS? Let's assume I set the locationType in config to auto. I'd like to know, when the app runs, inside an initializer, whether hash or history is being used.

Can I do this? Thank you.

Upvotes: 1

Views: 204

Answers (1)

Kit Sunde
Kit Sunde

Reputation: 37075

It took some digging around, but you can lookup the location attached to the router and compare it against the relevant cases.

const hashLocation = this.container.lookup('location:hash');
const historyLocation = this.container.lookup('location:history');
const currentLocation = this.container.lookup('router:main').get('location');
if(hashLocation === currentLocation){
   // Do thing
}else if(historyLocation === currentLocation) {
   // Do other thing
}else{
   // Fail whale.
}

Upvotes: 2

Related Questions