【问题标题】:In meteor How do I create a multichatroom app with unique urls for different rooms?在流星中,如何为不同的房间创建一个具有唯一 URL 的多聊天室应用程序?
【发布时间】:2013-02-06 02:29:52
【问题描述】:

我的基本聊天室正常工作(单页),但我想在浏览到我的 URL 时生成一个独特的聊天室。例如。用户浏览到 chatroom.com 并被重定向到 chatrooom.com/room1,然后她/他可以与朋友分享该 URL 以与之聊天。我该怎么做?

【问题讨论】:

    标签: node.js meteor


    【解决方案1】:

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

    mrt install router
    

    在您的客户端 js 中

    //In your chat query add something to localise your chat messages for your room e.g (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,它将仅加载 room 值为 lobby 的消息。

    更多关于流星路由器的文档:https://github.com/tmeasday/meteor-router

    【讨论】:

    • @Akshat 这(以及许多其他人!)是很好的答案。 Jade 正在找你——你可以给她发邮件到 contact@meteor.com 吗?
    猜你喜欢
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 2021-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-04
    • 2013-09-28
    相关资源
    最近更新 更多