Meteor breadcrumb

℡╲_俬逩灬. 提交于 2019-12-04 12:37:00

问题


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.


回答1:


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( "/" );
}



回答2:


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.



来源:https://stackoverflow.com/questions/21091868/meteor-breadcrumb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!