0

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.

KarimS
  • 3,812
  • 9
  • 41
  • 64
  • current route path will be stored in application controller 'currentPath' property..you can set it globally by observing or you can send it to your component..http://stackoverflow.com/questions/18302463/get-current-route-name-in-ember – Ember Freak Jul 25 '16 at 19:35

1 Answers1

1
/ 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

J__
  • 636
  • 6
  • 20
  • do you know how i can learn how ember js controller/route/components work, i have read the official guide but the problem is that they don't show the relation between them – KarimS Jul 25 '16 at 19:31
  • 1
    Every controller has a route, which defines the 'model' (or 'content') property on the respective controller. Components are instantiated within the template of a controller, and represent encapsulated pieces of the user interface. – J__ Jul 25 '16 at 19:52