Meteorjs Iron Router:Router.current不是[object object]的函数

时间:2016-09-15 14:40:14

标签: javascript meteor iron-router

在尝试检索以下代码中的路由器路由名称时,我遇到了可能是一个简单的问题。当语句Router.current()执行时,它返回一个null对象,即使我在路由中指定了名称。谁知道我在这里做错了什么?

此文件已加载到我的/ lib /目录

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!');

      });

错误代码:

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) 

1 个答案:

答案 0 :(得分:0)

铁路由器在doc

上提到了这一行
  

"如果你在客户端,你可以使用Router.current()方法。"

所以你无法访问服务器端的Router.current。