Search code examples
javascriptember.jsroutesdeprecated

Is `route.transitionTo` deprecated?


2023 UPDATE

route.transitionTo was deprecated in favor of using the router service. See the answer from Andrey below for links.


Original POST and Answer

Ember logs a warning that transitionTo has been deprecated in favor of transitionToRoute. However, ember currently has route.transitionTo and controller.transitionTo. Only controller.transitionTo has a deprecation notice on the API and in the source code.

Is the notice that route.transitionTo is deprecated a bug, or is the idiomatic method of transitioning changing to this.controllerFor( routename ).transitionToRoute().

ANSWER: NOT DEPRECATED

Turned out I had a mixing using this.transitionTo that was supposed to be involved in route's only but was getting used in a controller, which made it harder to notice.


Solution

  • Yes, this.transitionTo in a route has been deprecated.

    See:

    The modern alternative is:

    import Route from '@ember/routing/route';
    import { inject as service } from '@ember/service';
    
    export default class TodoRoute extends Route {
      @service router;
    
      beforeModel() {
        this.router.transitionTo('todo');
      }
    }