Search code examples
javascriptember.jsember-router

Define a root path in the router with Ember


I'd like to know if it's possible to set a specific folder to be my root path for my routes/views/templates/controllers?

For example, my project looks something like this:

/controllers
  /base
  /main
    /index.js
    /welcome
      /index.js

/routes
  /base
  /main
    /index.js
    /welcome
      /index.js

/templates
  /main
    /index.hbs
    /welcome
      /index.hbs

/views
  /base
  /main
    /index.js
    /welcome
      /index.js

My main folder is my root folder for all my controllers, routes, templates and views.

Using the URL:

  • mywebsite.com would access the page in /main/index.js
  • mywebsite.com/welcome would access the page in /main/welcome/index.js

Thanks


Solution

  • You can accomplish this by supplying the root route an empty path:

    Router.map(function() {
      this.resource('main', { path: '' }, function() {
        this.resource('main.welcome', { path: 'welcome' }, function() {});
      });
    });
    

    mywebsite.com gives you main/index.js and mywebsite.com/welcome gives you main/welcome/index.js.