Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在meteor中动态更改页面标题_Meteor_Meteorite - Fatal编程技术网

如何在meteor中动态更改页面标题

如何在meteor中动态更改页面标题,meteor,meteorite,Meteor,Meteorite,我对Meteor和Meteor路由器有一些疯狂的问题,特别是Meteor订阅句柄的ready回调以及它们与路由器的相互作用。如果我按ID调用订阅,它工作得很好,如果我按“slug”调用,它就不工作 我在服务器上有两个出版物: Meteor.publish('singleChannel', function(id) { return id && Channels.find(id); }); Meteor.publish('singleChannelSlug', funct

我对Meteor和Meteor路由器有一些疯狂的问题,特别是Meteor订阅句柄的
ready
回调以及它们与路由器的相互作用。如果我按ID调用订阅,它工作得很好,如果我按“slug”调用,它就不工作

我在服务器上有两个出版物:

Meteor.publish('singleChannel', function(id) {
    return id && Channels.find(id);
});

Meteor.publish('singleChannelSlug', function(_slug) {
    return Channels.find({slug:_slug});
});
client/main.js
中,我订阅了两份出版物:

singleChannelSlugHandle = Meteor.subscribe('singleChannelSlug', Session.get('currentChannelSlug'), function () {
    console.log('singleChannelSlug is ready() ');
});

singleChannelIdHandle = Meteor.subscribe('singleChannel', Session.get('currentChannelId'),function () {
    console.log('singleChannelIdHandle ready');
});
在路由器中,我有:

Meteor.Router.add({

'/channel/:slug': {
    as:'channelPage',
    to: function () {
        console.log('route1');
        if (singleChannelSlugHandle.ready()) {
            console.log( 'ready();', Channels.findOne({slug:Session.get('currentChannelSlug')}) );
            Session.set('currentChannelId', Channels.findOne({slug:Session.get('currentChannelSlug')})._id );
            return 'channelPage';
        } else {
            return 'spinner';
        };
    },
    and: function(slug) {
        Session.set('currentChannelSlug', slug);
    }
}
}))

这是console.log()输出:

现在应该做的是,
singleChannelSlugHandle
一旦准备就绪,它就会获取_id并将其写入会话并导航到页面。但不管出于什么原因,它都不起作用。永远不会调用console.log('ready();')


奇怪的是,如果我更改文件并保存,它只工作一次。如果我使用just ID重写路由,它也可以工作,但我需要它来处理slug,因为我需要比抽象ID更漂亮的URL。我已经在这上面做了4-5个小时了,无法首先弄清楚它,我不认为
to
的回调是被动的,所以尽管sub的
ready()
方法是被动的,
to
回调将不会重新运行

其次,在发布中始终返回光标:

Meteor.publish('singleChannel', function(id) {
    return /*id &&*/ Channels.find(id);
});

最后,使用Iron Router——这正是您想要的(请参见
waitOn

这是一个旧路由器,不再支持,请尝试使用IronRouter/谢谢。抱歉,我以为我解决了问题,但回到这里,看到了你的答案。
Meteor.publish('singleChannel', function(id) {
    return /*id &&*/ Channels.find(id);
});