understand new mongo id and use it with iron-router

后端 未结 2 1028
旧时难觅i
旧时难觅i 2021-02-10 18:55

i have a simple post route that looks for the post _id. The problem is that the pathFor helper creates a path like this:

ObjectID(\"52         


        
2条回答
  •  既然无缘
    2021-02-10 19:15

    Can you try this:

    this.route("post", {
        path: "/post/:stringId",
    
        waitOn:function(){
            NProgress.start();
            Meteor.subscribe("Teams");
        },
    
        before: function () {
            NProgress.done();
        },
    
        data: function () {
            Post = Posts.findOne({_id: Meteor.ObjectId(this.params.stringId)});
        }
    });
    

    Now when you go to post/52e16453431fc2fba4b6d6a8 you should be able to see the correct post.

    I am actually planning on using iron-router and objectid's in my application and thinking that this pattern would work.

    I have not tried it yet, but let me know if there is a problem and I'll create a small test app to work it out.

提交回复
热议问题