Skip to content

Latest commit

 

History

History
97 lines (68 loc) · 2.42 KB

no-private-routing-service.md

File metadata and controls

97 lines (68 loc) · 2.42 KB

ember/no-private-routing-service

💼 This rule is enabled in the ✅ recommended config.

Disallow the use of:

  • The private -routing service
  • The private _routerMicrolib property
  • The private router:main property

There has been a public router service since Ember 2.16 and using the private routing service should be unnecessary.

Examples

Examples of incorrect code for this rule:

import Component from '@ember/component';
import { inject as service } from '@ember/service';

export default Component.extend({
  routing: service('-routing')
});
import Component from '@ember/component';

export default class MyComponent extends Component {
  @service('-routing') routing;
}
// When `catchRouterMicrolib` option is enabled.

import Component from '@ember/component';

export default class MyComponent extends Component {
  @service('router') router;

  get someMethod() {
    return this.router._routerMicrolib.activeTransition;
  }
}
// When `catchRouterMain` option is enabled.

import Component from '@ember/component';
import { getOwner } from '@ember/application';

export default class MyComponent extends Component {
  someFunction() {
    const router = getOwner(this).lookup('router:main');
    // ...
  }
}

Examples of correct code for this rule:

import Component from '@ember/component';
import { inject as service } from '@ember/service';

export default Component.extend({
  router: service('router')
});
import Component from '@ember/component';

export default class MyComponent extends Component {
  @service
  router;
}

Configuration

Name Description Type Default
catchRouterMain Whether the rule should catch usages of the private property router:main. Boolean true
catchRouterMicrolib Whether the rule should catch usages of the private property _routerMicrolib. Boolean true

References

Router RFC