避免服务器端路由上的全局 onBeforeAction 方法

Avoiding global onBeforeAction methods on a server side route

我有一个用于 Facebook 共享的服务器端路由(因为现在它需要 URL)

this.route('share',{
    path: '/share',
    where: 'server'
}).get(function(data){
    var query = data.query;

    this.response.write('<html>');
    this.response.write('<head>');
    // content type is text/html by default
    this.response.write('<title></title>');

    if(query){
        for(var prop in query){
            if(query.hasOwnProperty(prop)){
                this.response.write('<meta property="'+prop+'" content="'+query[prop]+'" />');
            }
        }
    }

    this.response.write('</head>');
    this.response.write('<body></body>');
    this.response.write('</html>');

    this.response.end();
});

但是我的全局 Router.onBeforeAction() 函数仍然被调用,它使用 jQuery(动画)——这会导致服务器端出现问题。

有没有办法跳过全局挂钩,或者我应该只检查是否定义了 jQuery?

根据 iron:router guide,您应该使用 except 选项声明全局 onBeforeAction 挂钩:

Router.onBeforeAction(yourGlobalHook, {
  except: ['share']
});