Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 使用Router.go设置模板数据上下文_Meteor_Iron Router - Fatal编程技术网

Meteor 使用Router.go设置模板数据上下文

Meteor 使用Router.go设置模板数据上下文,meteor,iron-router,Meteor,Iron Router,使用iron router,我可以设置模板的数据上下文,如下所示: Router.route('hello',{data:{问候语:'hello'}}) 因此,如果我的hello.html如下所示: <template name="hello"> <h1>{{greeting}}</h1> </template> 但我得到的只是一个无聊的你好。可以这样设置数据吗?如果Router.go中的第二个参数不是用于数据,那么它用于什么呢?是的,应该可

使用iron router,我可以设置模板的数据上下文,如下所示:

Router.route('hello',{data:{问候语:'hello'}})

因此,如果我的
hello.html
如下所示:

<template name="hello">
  <h1>{{greeting}}</h1>
</template>

但我得到的只是一个无聊的你好。可以这样设置数据吗?如果Router.go中的第二个参数不是用于数据,那么它用于什么呢?

是的,应该可以。第二个参数作为参数传递给route函数,因此需要相应地设置该参数。试试这个:

Router.route('/hello/:greeting', {
  template: 'hello',
  data: function() {
    return {greeting: this.params.greeting};
  }
});
现在您可以拨打:

Router.go('hello', {greeting: 'Whazaaaaaaa'})

我是否需要在路由中使用:\问候语?this.params取消定义,例如:Router.route('/hello/:\问候语',{data:{问候语:this.params.\问候语?this.params.问候语:'hello'});对不起我的不好,更新了答案。代码现在可以工作了,所以第二个参数不是数据,它只是用来设置url路由中使用的参数?
Router.go('hello', {greeting: 'Whazaaaaaaa'})