Reputation: 1060
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
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