Meteor.subscribe("users"); let chatManager = new ChatManager(Chats); // set up the main template the the router will use to build pages Router.configure({ layoutTemplate: "ApplicationLayout" }); // specify the top level route, the page users see when they arrive at the site Router.route("/", function () { console.log("Routing root /"); this.render("navbar", { to: "header" }); this.render("lobby_page", { to: "main" }); }); // specify a route that allows the current user to chat to another users Router.route("/chat/:_id", { subscriptions: function () { // Meteor._debug("Subscriptions"); return Meteor.subscribe("chats"); }, action: function (req) { // Meteor._debug("Action", req.url); if (this.ready()) { console.log("- Now ready"); // The user they want to chat to has id equal to the id sent in after /chat/... const otherUserId = this.params._id; const myId = Meteor.userId(); chatManager.assignChatId(myId ? myId : "anon", otherUserId ? otherUserId : "anon", Session); if (Session.get("chatId")) { this.render("navbar", { to: "header" }); this.render("chat_page", { to: "main", data: function () { const other = Meteor.users.findOne({ _id: otherUserId }); // console.log("-- Routing data, other: " + (other ? other.profile.username : "not available")); return { other: other }; } }); } else { this.render("navbar", { to: "header" }); this.render("Error", { to: "main", data: new Meteor.Error("no-chat", `Could not find a chat between ${myId} and ${otherUserId}.`) }); } } else { console.log("- Not yet ready"); this.render("Loading"); } } });