Search code examples
meteoriron-router

meteor Tracker.autorun to get current route(Cannot read property 'route' of null)


I have the following code:

    Tracker.autorun(function () {
      var currentRouter = Router.current().route.getName()
      console.log('Current route is:',currentRouter);
    });

I get the following error in the console.

Cannot read property 'route' of null

I am trying to get the current route name everytime the router changes the path.


Solution

  • take a look at the hooks

    you could use Router.onBeforeAction(function () { for this. It will callback before every action on the router.