3

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/".

1
  • replaced Router.current().route.getName() with Router.current().route._path Commented Jun 9, 2015 at 12:53

3 Answers 3

10

Try:

Router.current().route.path()
2
  • first one returns "secondPage" and second returns "/secondPage" - the second is what I have been looking for, Thanks Commented Jun 9, 2015 at 12:55
  • 1
    Use the public method instead of the private attribute : Router.current().route.path().
    – saimeunt
    Commented Jun 9, 2015 at 12:56
2
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)

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.