Best Practices in Templates for Active Routes

Alright, so here’s a “magic” feature of Ember I wish I had more control over. Active Route.

LinkTo is fantastic in how it adds an “active” class automatically to all linked routes, but wouldn’t it be smashing if we could also access that state in some sort of conditional? Even with a custom helper it would be pretty graceful… ie.

ifRoute App.Router.current
  p the route is active
else
  linkTo 'foo.bar'

The only alternative I’ve found involves writing a lot of methods in setupController…

Please let me know if I’m way off base and there’s a really easy solution available.

4 Likes

you could easily write some helper for this. The code for it in the LinkView is here More generally this show how to bind to the current route for whatever your intent.

I would go with a mix of the linkTo/LinkView code and the {{if}} helper code.