Search code examples
javascriptmeteoriron-router

Meteorjs Iron Router: Router.current is not a function at [object object]


I am running into what is likely a straightforward issue when attempting to retrieve the Routers route name that I have in the below code. When the statement Router.current() executes it returns back a null object even though I have specified the name in my route. Anyone know what I might be doing wrong here?

This file is loaded into my /lib/ directory

Router.route( '/webservices', { name: 'webservices', where: "server" } )
      .get( function() {
        var res = this.response;
        var routeName = Router.current().route.getName();
        clientIp = this.request.connection.remoteAddress;

        console.log(clientIp+' '+routeName);

        res.end('NGA Web Services are Online!');

      });

Error Code:

TypeError: Router.current is not a function at [object Object]. (app/lib/routes/webservice.js:4:25) at boundNext (packages/iron_middleware-stack/lib/middleware_stack.js:251:1) at runWithEnvironment (packages/meteor/dynamics_nodejs.js:110:1) at packages/meteor/dynamics_nodejs.js:123:1 at [object Object].urlencodedParser (/home/v601756/.meteor/packages/iron_router/.1.0.13.1922hfs++os+web.browser+web.cordova/npm/node_modules/body-parser/lib/types/urlencoded.js:84:40) at packages/iron_router/lib/router.js:277:1 at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1) at [object Object].hookWithOptions (packages/iron_router/lib/router.js:276:1) at boundNext (packages/iron_middleware-stack/lib/middleware_stack.js:251:1) at runWithEnvironment (packages/meteor/dynamics_nodejs.js:110:1) 

Solution

  • Iron router mentioned this line on the doc

    "If you're on the client, you can use the Router.current() method."

    So You can not access the Router.current on server side.