Base route in Ember-cli


#1

I have a base route app/routes/base.js that I want all other routes to inherit (extend) from, how can I best achieve this?

For example, I tried the following but it doesn’t work.

// app/routes/index.js
import Ember from './base';

export default Ember.Route.extend({
    ...
});


// app/routes/base.js
import Ember from 'ember';

export default Ember.Route.extend({
    ...
});

What is the standard recipe to follow in order to achieve this?


#2

Your inheritance is off. Try this in app/routes/index.js:

import Base from './base';

export default Base.extend({
  // ...
});

#3

I tried your suggestion but get the following error message:

Uncaught TypeError: Cannot read property 'extend' of undefined

#4

Nevermind, works now. Had Base.Route.extend instead of Base.extend.


#5

Does the distinction make sense? Ember.Route is a class that lives within the Ember namespace. You don’t need a namespace in an Ember CLI app, so you can just extend the class you import.