Search code examples
ember.jsember-cli

How to configure the rootURL for the production environment?


I'd like to host an Ember app in the /blog/ directory. I found the following code in the documentation to make that happen but I have trouble to make it work.

App.Router.reopen({
  rootURL: '/blog/'
});

At what position do I have to include this code or is there a better way to do it anyway? I'd like to fire up ember build --environment=production and than copy /dist/* to the /blog/ directory on the webserver.


Solution

  • To do that, you should set baseURL in config/environment.js:

    if (environment === 'production') {
      ENV.baseURL = '/blog/';
    }
    

    Also, if you encounter any issues with hash location setup or IE9 you could also use following code in app/router.js:

    import Ember from 'ember';
    import config from './config/environment';
    
    let Router = Ember.Router.extend({
      location: config.locationType,
      rootURL: config.baseURL
    });