在尝试检索以下代码中的路由器路由名称时,我遇到了可能是一个简单的问题。当语句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)
答案 0 :(得分:0)