How to Check Current Route in Iron Router Meteor

I am setting up a body helper for use with Iron Router to be used as {{route}}

:

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

      

But it Router.current().route.getName()

returns undefined instead of "/ thirdPage /".

+3


source to share


3 answers


Try:



Router.current().route.path()

      

+8


source


Router.current().route.path()

      

Works fine as long as you don't have routes with parameters, after which it will reconfigure unexpectedly

null

      



makes it rather unreliable in my opinion.

Iron.Location.get().path

      

This seems to be the most reliable method at the moment for getting your path with parameters (rather than full url including "http: //" like Router.current (). Url does)

+2


source


I use:

Router.current().url

      

This gets everything in your url bar, FYI

Router.current().params.yourParamName

      

This will get the content of your parameter

+1


source







All Articles