Sean Mackesey
Sean Mackesey

Reputation: 10939

Ember: Access name of active child route from parent

I have a pair of routes (parent and child) in EmberJS. I want to bind some attributes in the parent route's template to computed properties that depend on the identity of the active child route. I am aware that the {{link-to}} helper automatically sets the active class on its element when it matches the current route. However, I want to go beyond this functionality. How can I best get the name of the active child route in the parent controller?

Upvotes: 1

Views: 258

Answers (1)

handlebears
handlebears

Reputation: 2276

You have a few options. One is to use the RouterService and some computed properties.

There is a method called currentRouteName that returns the route as a period separated string.

Another option is to track state in your own Service. Any time that different parts of an app need to share state, a service of some sort is usually the answer.

The Router Service was added in 2.17. This answer applies from then through at least 3.x, and was written as of 3.1.

Upvotes: 6

Related Questions