Dariusz Sikorski
Dariusz Sikorski

Reputation: 4407

How to check current route in Iron Router Meteor

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

Upvotes: 3

Views: 2959

Answers (3)

soisystems
soisystems

Reputation: 194

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)

Upvotes: 2

jackkav
jackkav

Reputation: 582

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

Upvotes: 1

thodic
thodic

Reputation: 2259

Try:

Router.current().route.path()

Upvotes: 10

Related Questions