我正在研究调查/向导类型的流星应用程序.界面将只有两个导航按钮,其标题/值将根据给定用户当前所处的步骤动态确定.我的问题是:我应该在这两个按钮的定义中使用什么标记语法,以指示Iron Router更改路由.换句话说,在按钮定义中我应该放这个:this.redirect('/ anotherpath')?
如果模板中有一个按钮.如果您正在使用来自f3rland的hrefs检查答案.
HTML:
<button #id="mybutton>m<Button</button>
Run Code Online (Sandbox Code Playgroud)
你可以用javascript捕捉buttonpress事件
JS
Template.myTemplate.events({
'click #myButton': function(event, template) {
event.preventDefault();
Router.go('anotherpath');
}
});
Run Code Online (Sandbox Code Playgroud)
路由器应该如下所示:
Router.map(function() {
this.route('anotherpath', {
path: '/',
layoutTemplate: 'myLayout',
controller: myController
});
});
Run Code Online (Sandbox Code Playgroud)