流行的accounts-entry软件包中有一个与铁路由器相关的错误。我相信铁路由器的后期版本改为更好地作为中间件工作,因此调用Router.routes
在file的第87行,使用了以下代码:
_.each Router.routes, (route)->
exclusions.push route.name
# Change the fromWhere session variable when you leave a path
Router.onStop ->
# If the route is an entry route, no need to save it
if (!_.contains(exclusions, Router.current().route?.getName()))
Session.set('fromWhere', Router.current().path)
不幸的是,似乎没有在Router.rou上做_.each是一个解决方案,因为Router.routes不会返回并且对象中包含.name属性。
您如何获得具有最新铁路由器的所有路线的名称?
答案 0 :(得分:7)
这个有点棘手:在最新版本的iron:router
中,Router.routes
现在被定义为函数数组。
事实上,函数在JS中已经有一个默认的name
属性,其中包含函数在定义时分配的名称。
var myFunc = function funcName(){...};
console.log(myFunc.name); // == "funcName"
幸运的是,在数组的路由项上定义了getName
方法,您可以使用这段代码迭代所有路由并获取其名称:
_.each(Router.routes, function(route){
console.log(route.getName());
});