Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor breadcrumb

How do I implement a reactive breadcrumb with Meteor and iron-router?

Now I'm looking for the current path, triggered by a reactive session variable and then adding each link that corresponds to that route inside the DOM with jQuery.

like image 306
sergi Avatar asked Jan 13 '14 12:01

sergi


2 Answers

You can call Router.current().path inside a helper function and it will return the current path. Then split the path on / and return the array to your breadcrumbs template. The function is reactive, so updates will propagate:

Template.breadcrumbs.path = function() {
  return Router.current().path.split( "/" );
}
like image 162
m.jansink Avatar answered Oct 09 '22 04:10

m.jansink


With Meteor 1.0 and Iron.Router it would be:

Template.breadcrumbs.helpers({
  path: function() {
    return Router.current().route.path(this).split( "/" );
  }
});

Note that the way of adding methods to the template engine Template.breadcrumbs.path = function() {} is deprecated.

like image 37
Michael Avatar answered Oct 09 '22 05:10

Michael