javascript - Is `route.transitionTo` deprecated? - Stack Overflow

2023 UPDATEroute.transitionTo was deprecated in favor of using the router service. See the answer from

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.

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.

Share Improve this question edited Apr 12, 2023 at 7:18 runspired asked Dec 17, 2013 at 21:43 runspiredrunspired 2,6931 gold badge21 silver badges24 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

from a controller you should use controller.transitionToRoute (specifying that you want to transition a route) from a route you should use route.transitionTo and it makes sense that route is implied due to the context.

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

See:

  • RFC
  • Official deprecation notice

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');
  }
}

transitionTo should only throw a warning in a controller, You're most probably using transitionTo in some controller somewhere.

From within routes:

this.transitionTo('someRoute');

From within controllers:

this.transtionToRoute('someRoute');

Source: (http://github./emberjs/website/pull/964)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742348322a4426997.html

相关推荐

  • javascript - Is `route.transitionTo` deprecated? - Stack Overflow

    2023 UPDATEroute.transitionTo was deprecated in favor of using the router service. See the answer from

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信