kgish
January 18, 2015, 10:18am
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?
Your inheritance is off. Try this in app/routes/index.js
:
import Base from './base';
export default Base.extend({
// ...
});
kgish
January 18, 2015, 8:43pm
3
I tried your suggestion but get the following error message:
Uncaught TypeError: Cannot read property 'extend' of undefined
kgish
January 18, 2015, 8:45pm
4
Nevermind, works now. Had Base.Route.extend
instead of Base.extend
.
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.
2 Likes