如何在 Iron Router Meteor 中查看当前路线

How to check current route in Iron Router Meteor

我正在设置一个 body helper 与 Iron Router 一起使用 {{route}}:

Template.body.helpers({
  route: function(){
    alert(Router.current().route.getName());
  }
});

但是 Router.current().route.getName() returns 未定义而不是“/thirdPage/”。

尝试:

Router.current().route.path()

我使用:

Router.current().url

这会得到您 url 栏中的任何内容, 仅供参考

Router.current().params.yourParamName

这会得到你参数的内容

Router.current().route.path()

工作正常,直到你有带参数的路由,此时它突然重新调整

null

在我看来这很不可靠。

Iron.Location.get().path

似乎是目前获取带参数路径的最可靠方法(不是完整的 url,包括 "http://" as Router.current()。url确实)