How can I make Meteor templates available to targe

2019-09-02 14:29发布

问题:

I want to build a Blog, of sorts, with Meteor but, rather than just have a Blog such as platypus.meteor.com, I want to create a separate Meteor template for each Blog "post" and then send a link to select people such as "platypus.meteor.com/thispost"

In this way, the person would only see the post I intend them to see; to see others, they would have to guess at other values, such as "/thatpost", "/theotherpost" etc.

And in my case, if they stumbled across them, no big deal.

This is my plan:

Create one template at a time:

<template name="thispost">
    . . .
</template>

...and then allow access to that to whomever I apprise of its availability (that is, they simply enter the link I send them into their browser).

I don't know what sort of routing I need to set up; I'm open to either IronRouter or FlowRouter. At any rate, I want an URL like "platypus.meteor.com/thispost" (after a "meteor deploy platypus" of this project) to show the user the contents of that Template and nothing else.

So my question is: what do I have to do, routing-wise, to accomplish this?

回答1:

How about simply:

Router.route("/:templateName/:postId",{
  template: this.params.templateName,
  data: function(){ return Posts.findOne({ _id: this.params.postId })
});

Then you can generically share any post with any template and have the template name appear right in the route.