I have a large number of resources that use exactly the same logic. Each resource has a <resource>
route and a <resource>.show
route. I've defined BaseRoute
, BaseShowRoute
, BaseController
, BaseShowController
and corresponding templates to capture this common logic. I set the appropriate controller/templates on the route objects:
// routes/base.js
import Ember from 'ember';
export default Ember.Route.extend({
controllerName: 'base',
templateName: 'base'
});
// routes/base/show.js
import Ember from 'ember';
export default Ember.Route.extend({
controllerName: 'baseShow',
templateName: 'baseShow'
});
But in order to use these route prototypes with my resources, I have to have two modules for each resource:
// routes/<resource>.js
import BaseRoute from './base';
export default BaseRoute.extend({
});
// routes/<resource>/show.js
import BaseShowRoute from './base/show'
export default BaseShowRoute.extend({
});
This seems silly. I would like to specify that all of these resources should use BaseRoute
and BaseShowRoute
without needing to create these modules. It would be reasonable to have this option in Router.map
. Something like this:
Router.map(function(){
this.resource('articles', { extends: BaseRoute }, function() {
this.route('show', { path: ':article_id', extends: BaseShowRoute })
});
});
But to my knowledge there is nothing like the extends
option I'm using above.
The only documentation I can find for the route
and resource
methods invoked in Router.map
is in the Routing Guide. The only option that you can pass to these methods seems to be path
. The ember-cli user guide does say that you can override the base class for all generated routes if you define routes/basic.js, but this is not enough for me-- I need multiple base classes.
How can I get rid of my boilerplate route modules?