KarimS
KarimS

Reputation: 3892

getting route name from component

I have my problem with link-to help, I want to use it with bootstrap navigation, but I can't manage well active link state, so I'm trying to write a component, but I need to get the current route inside the component, so I can create the html element based on the route. I searched in the api reference, but didn't find nothing.

PS: I know there is an add-on to do that by I'm doing that to learn the framework.

sorry for my bad English.

Upvotes: 0

Views: 519

Answers (1)

J__
J__

Reputation: 635

/ controller.hbs
{{ my-component controller=this }}

# my-component.coffee
@get('controller.target') # this is the route

If you need the CURRENT route, as opposed to the route associated with the controller that your component is instantiated in, you would inject the application controller into your component, and get the current route.

applicationController: Ember.inject.controller('application')
currentPath:           Ember.computed.alias 'applicationController.currentPath'

http://emberjs.com/api/classes/Ember.Controller.html#property_target

Upvotes: 1

Related Questions