How to check current route in Iron Router Meteor

2.9k views Asked by At

I'm setting up a body helper for use with Iron Router to use as {{route}}:

Template.body.helpers({
  route: function(){
    alert(Router.current().route.getName());
  }
});

But Router.current().route.getName() returns undefined instead of "/thirdPage/".

3

There are 3 answers

2
thodic On BEST ANSWER

Try:

Router.current().route.path()
0
jackkav On

I use:

Router.current().url

This gets whatever is in your url bar, FYI

Router.current().params.yourParamName

This will get the content of your parameter

0
soisystems On
Router.current().route.path()

Works fine until you have routes with parameters, at which point it suddenly retuns

null

making it pretty unreliable in my opinion.

Iron.Location.get().path

Seems to be the most reliable method at the moment for getting your path with parameters (not the complete url including "http://" as Router.current().url does)