✅ The extends: 'recommended'
property in a configuration file enables this rule.
This rule disallows the usage of route-action
.
ember-route-action-helper was a popular addon used to add actions to a route without creating a separate controller. Given the changes in Ember since ember-route-action-helper was a widely used pattern, controllers are now encouraged and we want to discourage the use of route-action.
Most route actions should either be sent to the controller first or encapsulated within a downstream component instead. We should never be escaping the DDAU hierarchy to lob actions up to the route.
This rule forbids the following:
With the given route:
// app/routes/foo.js
export default class extends Route {
@action
updateFoo(baz) {
// ...
}
}
This rule allows the following:
With the given controller:
// app/controllers/foo.js
export default class extends Controller {
@action
updateFoo(baz) {
// ...
}
}
The example below shows how to migrate from route-action to controller actions.
// app/routes/posts.js
export default class extends Route {
model(params) {
return this.store.query('post', { page: params.page })
}
@action
goToPage(pageNum) {
this.transitionTo({ queryParams: { page: pageNum } });
}
}
// app/controllers/posts.js
export default class extends Controller {
queryParams = ['page'];
page = 1;
}
// app/routes/posts.js
export default class extends Route {
model(params) {
return this.store.query('post', { page: params.page })
}
}
// app/controllers/posts.js
export default class extends Controller {
queryParams = ['page'];
page = 1;
@action
goToPage(pageNum) {
this.transitionToRoute({ queryParams: { page: pageNum } });
}
}