meteor iron-router and getting the names of all routes for the accounts-entry package

安稳与你 提交于 2019-12-04 13:41:01

This one is a little tricky : in the latest version of iron:router, Router.routes is now defined as an array of functions.

Thing is, functions already have a default name property in JS which contains the name the function was assigned on definition.

var myFunc = function funcName(){...};
console.log(myFunc.name); // == "funcName"

Fortunately, there is a getName method defined on the route items of the array and you can use this piece of code to iterate over all routes and get their name :

_.each(Router.routes, function(route){
  console.log(route.getName());
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!