Javascript meteor iron路由器无法打印属性
所以我有路由器Javascript meteor iron路由器无法打印属性,javascript,meteor,iron-router,Javascript,Meteor,Iron Router,所以我有路由器 Router.route('/', function () { console.log("my message"); console.log(this.request.query.q); this.render('map'); }); 的urlhttp://localhost:3000/?q=somequery 当我删除console.logthis.request.query.q时,它工作正常,但添加此行会产生以下错误: Exception in callback
Router.route('/', function () {
console.log("my message");
console.log(this.request.query.q);
this.render('map');
});
的urlhttp://localhost:3000/?q=somequery
当我删除console.logthis.request.query.q时,它工作正常,但添加此行会产生以下错误:
Exception in callback of async function: TypeError: Cannot read property 'q' of undefined
为什么meteor找不到这个参数?来自文档
若url中有查询字符串或哈希片段,则可以使用this.params对象的查询和哈希属性访问这些字符串或哈希片段
// given the url: "/post/5?q=s#hashFrag"
Router.route('/post/:_id', function () {
var id = this.params._id;
var query = this.params.query;
// query.q -> "s"
var hash = this.params.hash; // "hashFrag"
});
试一试
this.params.q