Router: public API for current routes (dynamic breadcrumb)

I once wrote something like this:

template: function () {
    var template = [],
        controller = this.get('controller'),
        router = controller.container.lookup('router:main'),
        currentHandlerInfos = router.get('router.currentHandlerInfos');

    for (var i = 0; i < currentHandlerInfos.length; i++) {
        var name = Em.get(currentHandlerInfos[i], 'name');

        if (!(router.hasRoute(name) || router.hasRoute(name + '.index')) || name.endsWith('.index')) {
            continue;
        }

        var notLast = i < currentHandlerInfos.length - 1 && !Em.get(currentHandlerInfos[i + 1], 'name').endsWith('.index');

        template.push('<li' + (notLast ? '>' : ' class="active">'));
        if (notLast) {
            template.push('{{#linkTo "' + name + '"}}');
        }
        template.push(name);
        if (notLast) {
            template.push('{{/linkTo}}');
        }

        if (notLast) {
            template.push('<span class="divider">/</span>');
        }

        template.push('</li>');
    }

    return Em.Handlebars.compile(template.join("\n"));
}.property('controller.currentPath')