2016-09-15 80 views
0

我試圖檢索路由器路由名稱,在下面的代碼中可能是一個直截了當的問題。當語句Router.current()執行它時,即使我在路由中指定了名稱,也會返回一個空對象。任何人都知道我可能在這裏做錯了什麼?Meteorjs鐵路路由器:Router.current不是在[對象對象]的函數

此文件加載到我的/ 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

鐵路由器提到的doc

此行「如果你在客戶端上,您可以使用Router.current()方法。「

所以你不能訪問服務器端的Router.current。