Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access the name of the current route in meteor when using meteor-router?

Tags:

meteor

I'm building an app using meteor and meteor router, and I would like to make a template helper for checking if the route is a specific one ({{#ifRouteIs login}}{{/ifRouteIs}}).

like image 403
Diogenes Avatar asked Feb 17 '23 14:02

Diogenes


2 Answers

I had the same issue. Building on your answer, I found a working solution. It needs to go in the client side of Meteor.

Handlebars.registerHelper('ifRouteIs', function (routeName, options) { 
  if (Meteor.Router.page() === routeName) {
    return options.fn(this);
  }
  return options.inverse(this);
});
like image 139
Chet Avatar answered Mar 01 '23 23:03

Chet


According to meteor-router's README, you can get the current page with Meteor.Router.page(), so the helper might look like this:

Handlebars.registerHelper('ifRouteIs', function (routeName) {
  return Meteor.Router.page() === routeName;
});
like image 41
Diogenes Avatar answered Mar 02 '23 01:03

Diogenes