为了使你的路由URL在模板中,你应该使用pathFor:
{{#with strategy}}
{{/with}}
pathFor需要一个路径名作为参数,并呈现使用当前数据上下文的URL,您应该将其设置为网址所依据的文档。
你的路由定义是坏了,应该是这样的:他们总是用/开头,并且可以包含使用此语法命名参数:
this.route("strategy",{
// specify the strategy _id as an URL component instead of query parameter
path:"/strategy/:_id",
data: function(){
// this.params._id lookups for URL components, not query params
var strategy=Strategies.findOne(this.params._id);
return {
strategy:strategy
};
}
});
有你的路线形成正确的路径是很重要的:parameterName,这些参数可以在路线功能中使用this.params.parameterName进行检索。
编辑:
为了得到一个正确的路径JS,使用Router.path,这是什么pathFor无论如何使用:
Template.strategy.helpers({
anchor:function(strategy){
var href = Router.path("strategy",strategy);
return "Link";
}
});
你需要渲染使用三层括号标记你的锚。
{{{anchor strategy}}}