Breadcrumbs with ember

So today I refactored some part of our application and I redid the breadcrumbs part. All routes are stored in App.Router.router.currentHandlerInfos. So by using this, I could compute the needed informations and put that in a controller:

App.BreadcrumbsController = Ember.Controller.extend(
  needs: "application"

  breadContent: Ember.computed ->
    routes = App.get("Router.router.currentHandlerInfos")
    segments =, (route) ->
      if route.isDynamic and route.context
        name = route.context.get("id")
        context = route.context
        dotIndex = _.lastIndexOf(, '.')+1
        name = Ember.String.capitalize(

      return {
        name: name
        context: context
    return segments

The _.tail is used to get rid of the "application" route which is always here. Then for the route name, I only take what is after the last dot, so a route: 'user.edit' will appear as 'edit'. Note the dependency on ApplicationController.currentPath. This make sure the property is updated whenever the route changes.

The template look like this:

<ul class="breadcrumb">
  <li>{{#linkTo 'index'}}<i class="icon-home"></i>Home{{/linkTo}}</li>
  {{#each segment in breadContent}}
  <span class="divider">&gt;</span>
  <a href="javascript://" {{action gotoRoute segment}} >{{}}</a>

And we also need to add the gotoRoute in the controller:

  gotoRoute: (routeOpt)->
    if routeOpt.context
      @transitionToRoute(routeOpt.routePath, routeOpt.context)

This action is here because ember's linkTo helper cannot get a route with a variable name.
Finally, wherever you need the breadcrumbs, call it with {{ render breadcrumbs }}

And that's it, now you have easy breadcrumbs, which links to the right part of the app. Enjoy