Meteor breadcrumb
Asked Answered
P

2

5

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.

Pitsaw answered 13/1, 2014 at 12:55 Comment(0)
R
7

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( "/" );
}
Rochet answered 14/1, 2014 at 16:20 Comment(1)
Thank you, I didn't knew that Router.current() is reactive!Pitsaw
B
5

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.

Brackish answered 11/12, 2014 at 15:52 Comment(1)
I created a more advanced plugin for meteor which works with the iron router to generate breadcrumbs: atmospherejs.com/monbro/iron-router-breadcrumbBrackish

© 2022 - 2024 — McMap. All rights reserved.