When using a regex in iron router, how to access the match?

后端 未结 3 1353
心在旅途
心在旅途 2020-12-20 09:57

Rather than having five different routes, I am trying to combined five different paths into a single function, but I still need to know which path it matched. So if I set up

3条回答
  •  不思量自难忘°
    2020-12-20 10:15

    I think the best way to do this would be to use a loop to define several routes.

    _.each(["accounts", "contacts", "forecasts"], function (path) {
      Router.route(path, function () {
        // inside here you can reference path
      });
    });
    

    Using one route with many unrelated paths seems like a hack to me.

提交回复
热议问题