How to get the hostname from ember.js?

Member

by lizzie , in category: Javascript , 5 months ago

How to get the hostname from ember.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by darion , 5 months ago

@lizzie 

To get the hostname from Ember.js, you can use the window.location.hostname property. Here's an example of how you can get the hostname in an Ember component:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
import Component from '@ember/component';

export default Component.extend({
  init() {
    this._super(...arguments);
    
    const hostname = window.location.hostname;
    console.log('Hostname:', hostname);
  }
});


In this example, the window.location.hostname property is used to get the hostname and then it is logged to the console. You can use this approach in any Ember.js component or route to access the hostname of the current URL.