在meteor如何创build一个multichatroom应用程序与不同的房间独特的url?

我有基本的聊天室工作(单页),但我想生成一个独特的一个,当我浏览我的url。 例如用户浏览到chatroom.com并被redirect到chatrooom.com/room1,然后他/她可以与朋友分享该url与之聊天。 我怎么去做这个?

你需要一个路由器,你可以使用骨干或我个人最喜欢的meteor路由器(通过陨石安装):

mrt install router 

在你的客户端JS

 //In your chat query add something to localise your chat messages for your room eg (if you're using handlebars): Template.messages.message = function() { //assuming messages contains your collection of chats return messages.find({room:Session.get("room")}) //get the room name set in the router }; 

并为您的路由器(也在客户端JS):

 Meteor.Router.add({ '/': 'home', '/rooms/:id': function(id) { Session.set("room",id); //set the room for the template return "messages"; //If you're template is called messages }, '*': 'not_found' 

});

所以,如果你要加载/rooms/lobby它只会加载与lobbyroom价值的消息。

meteor路由器的更多文档在这里: https : //github.com/tmeasday/meteor-router