Meteor-在每次加载页面时执行代码

Meteor-在每次加载页面时执行代码,meteor,iron-router,Meteor,Iron Router,我想在任何页面加载时执行一个函数 像Meteor.startup()和Template.myTemplate.onRendered()这样的东西不是我想要的,因为它们在应用程序加载时只触发一次 基本上,我需要一个每次URL更改都会触发的事件,是吗?您可以使用onRun或onBeforeAction在每次路由更改时运行任意代码 Router.onRun(function(){ console.log('onRun', this.current().route.getName()); thi

我想在任何页面加载时执行一个函数

Meteor.startup()
Template.myTemplate.onRendered()
这样的东西不是我想要的,因为它们在应用程序加载时只触发一次


基本上,我需要一个每次URL更改都会触发的事件,是吗?

您可以使用
onRun
onBeforeAction
在每次路由更改时运行任意代码

Router.onRun(function(){
  console.log('onRun', this.current().route.getName());
  this.next();
});

Router.onBeforeAction(function(){
  console.log('onBeforeAction', this.current().route.getName());
  this.next();
});
使用此占位符代码可检测此代码实际运行的时间

onRun
在每次路线更改时只运行一次。(适用于分析相关的东西)
当修改当前路由数据上下文时,
onBeforeAction
将反应性地重新运行。

您使用的是什么路由器?