使用 Meteor & Iron 的临时路由:路由器?

Temporary Routes Using Meteor & Iron: Router?

是否可以使用 Iron: Router 在 Meteor 中创建临时路由?

如何应用:当用户提出问题时,他们将被重定向到带有我提供的自定义参数的聊天室。当用户在聊天室完成并离开时,我希望这条路线被销毁。

例如:/chat/[我设置的自定义参数]

在你的路线中使用 : 来表示一个可以改变但必须的值(即 /chatroom/12345 可以,但 /chatroom 不会)

Router.route('/chatroom/:chatId', {
    name: 'chatroom',
    template: 'chatroom',
    layoutTemplate:"myLayout",
    data: function () {
        return ChatRoomData.findOne({_id:this.params.chatId});
    }
});

或者,您也可以通过添加 ?

使传入的参数可选
Router.route('/chatroom/:chatId?', {
    name: 'chatroom',
    template: 'chatroom',
    layoutTemplate:"myLayout",
    onBeforeAction: function () {
        if (!!this.params.chatId)
           //Do Something with the chatId
           this.render('specificChatRoom', {
              data: function () {
                  return ChatRoomData.findOne({_id:this.params.chatId});
              }
           });
        else
           //Do Something else
           this.render('mainChatRoom');

        this.next();
    }
});