1
我有'文章'和詳細視圖的列表視圖。這些航線使用鐵路路由器無法訪問流星中的參數
this.route("articles", {path: "/articles", controller: "ArticlesController"});
this.route("article", {path: "/articles/:_id", controller: "ArticleController"});
內模板/文章,我有一個鏈接到詳細信息視圖
<a href="{{pathFor 'article' id=this._id }}"><i class="portlet-icon portlet-icon-maximize"></i></a>
頁面被正確地嵌入ID呈現,如:
<a href="/articles/gb6KgxbnfBeynz4rH">
<i class="portlet-icon portlet-icon-maximize"></i>
</a>
在我的控制器關聯的路線,我不能訪問參數,它是空的。
this.ArticleController = RouteController.extend({
template: "Article",
onBeforeAction: function() {
this.next();
},
action: function(){
if (this.isReady()) {
this.render();
} else {
this.render("loading");
}
},
isReady: function() {
var ready = true;
var subs = [ Meteor.subscribe('singleArticle')];
_.each(subs, function(sub) {
if(!sub.ready())
ready = false;
});
return ready;
},
data: function() {
console.log(Iron.Location.get());
console.log("params: " + this.params);
return {
article: Articles.findOne({articleId:this.params._id}, {})
};
}
});
從JavaScript控制檯我可以看到_id與傳遞的url,但我不能訪問this.params
怎麼樣' Router.current()。params'? – Sindis
你確定你使用的是最新版本的'iron-router'嗎? –
鐵:[email protected] – ardochhigh